<commit_before>#ifndef INCLUDE_AL_GRAPHICS_MESH_HPP
#define INCLUDE_AL_GRAPHICS_MESH_HPP

/*	Allocore --
	Multimedia / virtual environment application class library
	
	Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology, UCSB.
	Copyright (C) 2006-2008. The Regents of the University of California (REGENTS). 
	All Rights Reserved.

	Permission to use, copy, modify, distribute, and distribute modified versions
	of this software and its documentation without fee and without a signed
	licensing agreement, is hereby granted, provided that the above copyright
	notice, the list of contributors, this paragraph and the following two paragraphs 
	appear in all copies, modifications, and distributions.

	IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
	SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
	OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
	BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

	REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
	THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
	HEREUNDER IS PROVIDED "AS IS". REGENTS HAS  NO OBLIGATION TO PROVIDE
	MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


	File description:
	A generic mesh object for vertex-based geometry

	File author(s):
	<NAME>, 2010, <EMAIL>
	<NAME>, 2010, <EMAIL>
	<NAME>, 2010, <EMAIL>
*/

#include "allocore/math/al_Vec.hpp"
#include "allocore/math/al_Matrix4.hpp"
#include "allocore/types/al_Buffer.hpp"
#include "allocore/types/al_Color.hpp"

namespace al{

/// Stores buffers related to rendering graphical objects

/// A mesh is a collection of buffers storing vertices, colors, indices, etc.
/// that define the geometry and coloring/shading of a graphical object.
class Mesh {
public:

	typedef Vec3f			Vertex;
	typedef Vec3f			Normal;
	//typedef Vec4f			Color;
	typedef Vec2f			TexCoord2;
	typedef Vec3f			TexCoord3;
	typedef unsigned int	Index;
	typedef Vec3i			TriFace;
	typedef Vec4i			QuadFace;

	/// @param[in] primitive	renderer-dependent primitive number
	Mesh(int primitive=0): mPrimitive(primitive){}

	/// Get corners of bounding box of vertices
	
	/// @param[out] min		minimum corner of bounding box
	/// @param[out] max		maximum corner of bounding box
	void getBounds(Vec3f& min, Vec3f& max) const;

	/// Get center of vertices
	Vertex getCenter() const;


	// destructive edits to internal vertices:

	/// Convert indices (if any) to flat vertex buffers
	void decompress();

	/// Extend buffers to match number of vertices
	
	/// This will resize all populated buffers to match the size of the vertex
	/// buffer. Buffers are extended by copying their last element.
	void equalizeBuffers();
	
	/// Append buffers from another mesh:
	void merge(const Mesh& src);

	/// Reset all buffers
	Mesh& reset();

	/// Scale all vertices to lie in [-1,1]
	void unitize();

	void scale(double x, double y, double z);
	void scale(Vec3f v) { scale(v[0], v[1], v[2]); }
	void scale(double s) { scale(s, s, s); }
	void translate(double x, double y, double z);
	void translate(Vec3f v) { translate(v[0], v[1], v[2]); }
	
	/// Transform vertices by projective transform matrix
	
	/// @param[in] m		projective transform matrix
	/// @param[in] begin	beginning index of vertices
	/// @param[in] end		ending index of vertices, negative amount specify distance from one past last element
	template <class T>
	void transform(const Mat<4,T>& m, int begin=0, int end=-1);

	/// Generates normals for a set of vertices
	
	/// This method will generate a normal for each vertex in the buffer
	/// assuming the drawing primitive is a triangle. Face normals are generated
	/// if no indices are present, and averaged vertex normals are generated
	/// if indices are present. This will replace any normals currently in use.
	///
	/// @param[in] normalize	whether to normalize normals
	void generateNormals(bool normalize=true, bool equalWeightPerFace=false);
	
	void invertNormals();
	
	/// Creates a mesh filled with lines for each normal of the source
	
	/// @param[out] mesh		normal lines
	/// @param[in]  length		length of normals
	/// @param[in]  perFace		whether normals line should be generated per 
	///							face rather than per vertex
	void createNormalsMesh(Mesh& mesh, float length=0.1, bool perFace=false);

	/// Ribbonize curve
	
	/// @param[in] width			Width of ribbon
	/// @param[in] faceBitangent	If true, surface faces bitangent vector of curve.
	///								If false, surface faces normal vector of curve.
	void ribbonize(float width, bool faceBitangent=false){
		ribbonize(&width, 0, faceBitangent);
	}

	/// Ribbonize curve
	
	/// @param[in] widths			Array specifying width of ribbon at each point along curve
	/// @param[in] widthsStride		Stride factor of width array
	/// @param[in] faceBitangent	If true, surface faces bitangent vector of curve.
	///								If false, surface faces normal vector of curve.	
	void ribbonize(float * widths, int widthsStride=1, bool faceBitangent=false);


	int primitive() const { return mPrimitive; }
	const Buffer<Vertex>& vertices() const { return mVertices; }
	const Buffer<Normal>& normals() const { return mNormals; }
	const Buffer<Color>& colors() const { return mColors; }
	const Buffer<Colori>& coloris() const { return mColoris; }
	const Buffer<TexCoord2>& texCoord2s() const { return mTexCoord2s; }
	const Buffer<TexCoord3>& texCoord3s() const { return mTexCoord3s; }
	const Buffer<Index>& indices() const { return mIndices; }


	/// Append index to index buffer
	void index(unsigned int i){ indices().append(i); }

	/// Append indices to index buffer	
	template <class Tindex>
	void index(const Tindex * buf, int size, int indexOffset=0){
		for(int i=0; i<size; ++i) index(buf[i] + indexOffset); }


	/// Append color to color buffer
	void color(const Color& v) { colors().append(v); }

	/// Append color to color buffer
	void color(const Colori& v) { coloris().append(v); }

	/// Append color to color buffer
	void color(const HSV& v) { colors().append(v); }

	/// Append color to color buffer
	void color(float r, float g, float b, float a=1){ color(Color(r,g,b,a)); }
	
	/// Append color to color buffer
	template <class T>
	void color(const Vec<4,T>& v) { color(v[0], v[1], v[2], v[3]); }

	/// Append floating-point color to integer color buffer
	void colori(const Color& v) { coloris().append(Colori(v)); }

<commit_msg>fix for appending buffers to mesh index (wrong template type)<commit_after>#ifndef INCLUDE_AL_GRAPHICS_MESH_HPP
#define INCLUDE_AL_GRAPHICS_MESH_HPP

/*	Allocore --
	Multimedia / virtual environment application class library
	
	Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology, UCSB.
	Copyright (C) 2006-2008. The Regents of the University of California (REGENTS). 
	All Rights Reserved.

	Permission to use, copy, modify, distribute, and distribute modified versions
	of this software and its documentation without fee and without a signed
	licensing agreement, is hereby granted, provided that the above copyright
	notice, the list of contributors, this paragraph and the following two paragraphs 
	appear in all copies, modifications, and distributions.

	IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
	SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
	OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
	BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

	REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
	THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
	PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
	HEREUNDER IS PROVIDED "AS IS". REGENTS HAS  NO OBLIGATION TO PROVIDE
	MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


	File description:
	A generic mesh object for vertex-based geometry

	File author(s):
	<NAME>, 2010, <EMAIL>
	<NAME>, 2010, <EMAIL>
	<NAME>, 2010, <EMAIL>
*/

#include "allocore/math/al_Vec.hpp"
#include "allocore/math/al_Matrix4.hpp"
#include "allocore/types/al_Buffer.hpp"
#include "allocore/types/al_Color.hpp"

namespace al{

/// Stores buffers related to rendering graphical objects

/// A mesh is a collection of buffers storing vertices, colors, indices, etc.
/// that define the geometry and coloring/shading of a graphical object.
class Mesh {
public:

	typedef Vec3f			Vertex;
	typedef Vec3f			Normal;
	//typedef Vec4f			Color;
	typedef Vec2f			TexCoord2;
	typedef Vec3f			TexCoord3;
	typedef unsigned int	Index;
	typedef Vec3i			TriFace;
	typedef Vec4i			QuadFace;

	/// @param[in] primitive	renderer-dependent primitive number
	Mesh(int primitive=0): mPrimitive(primitive){}

	/// Get corners of bounding box of vertices
	
	/// @param[out] min		minimum corner of bounding box
	/// @param[out] max		maximum corner of bounding box
	void getBounds(Vec3f& min, Vec3f& max) const;

	/// Get center of vertices
	Vertex getCenter() const;


	// destructive edits to internal vertices:

	/// Convert indices (if any) to flat vertex buffers
	void decompress();

	/// Extend buffers to match number of vertices
	
	/// This will resize all populated buffers to match the size of the vertex
	/// buffer. Buffers are extended by copying their last element.
	void equalizeBuffers();
	
	/// Append buffers from another mesh:
	void merge(const Mesh& src);

	/// Reset all buffers
	Mesh& reset();

	/// Scale all vertices to lie in [-1,1]
	void unitize();

	void scale(double x, double y, double z);
	void scale(Vec3f v) { scale(v[0], v[1], v[2]); }
	void scale(double s) { scale(s, s, s); }
	void translate(double x, double y, double z);
	void translate(Vec3f v) { translate(v[0], v[1], v[2]); }
	
	/// Transform vertices by projective transform matrix
	
	/// @param[in] m		projective transform matrix
	/// @param[in] begin	beginning index of vertices
	/// @param[in] end		ending index of vertices, negative amount specify distance from one past last element
	template <class T>
	void transform(const Mat<4,T>& m, int begin=0, int end=-1);

	/// Generates normals for a set of vertices
	
	/// This method will generate a normal for each vertex in the buffer
	/// assuming the drawing primitive is a triangle. Face normals are generated
	/// if no indices are present, and averaged vertex normals are generated
	/// if indices are present. This will replace any normals currently in use.
	///
	/// @param[in] normalize	whether to normalize normals
	void generateNormals(bool normalize=true, bool equalWeightPerFace=false);
	
	void invertNormals();
	
	/// Creates a mesh filled with lines for each normal of the source
	
	/// @param[out] mesh		normal lines
	/// @param[in]  length		length of normals
	/// @param[in]  perFace		whether normals line should be generated per 
	///							face rather than per vertex
	void createNormalsMesh(Mesh& mesh, float length=0.1, bool perFace=false);

	/// Ribbonize curve
	
	/// @param[in] width			Width of ribbon
	/// @param[in] faceBitangent	If true, surface faces bitangent vector of curve.
	///								If false, surface faces normal vector of curve.
	void ribbonize(float width, bool faceBitangent=false){
		ribbonize(&width, 0, faceBitangent);
	}

	/// Ribbonize curve
	
	/// @param[in] widths			Array specifying width of ribbon at each point along curve
	/// @param[in] widthsStride		Stride factor of width array
	/// @param[in] faceBitangent	If true, surface faces bitangent vector of curve.
	///								If false, surface faces normal vector of curve.	
	void ribbonize(float * widths, int widthsStride=1, bool faceBitangent=false);


	int primitive() const { return mPrimitive; }
	const Buffer<Vertex>& vertices() const { return mVertices; }
	const Buffer<Normal>& normals() const { return mNormals; }
	const Buffer<Color>& colors() const { return mColors; }
	const Buffer<Colori>& coloris() const { return mColoris; }
	const Buffer<TexCoord2>& texCoord2s() const { return mTexCoord2s; }
	const Buffer<TexCoord3>& texCoord3s() const { return mTexCoord3s; }
	const Buffer<Index>& indices() const { return mIndices; }


	/// Append index to index buffer
	void index(unsigned int i){ indices().append(i); }

	/// Append indices to index buffer	
	template <class Tindex>
	void index(const Tindex * buf, int size, Tindex indexOffset=0){
		for(int i=0; i<size; ++i) index(buf[i] + indexOffset); }


	/// Append color to color buffer
	void color(const Color& v) { colors().append(v); }

	/// Append color to color buffer
	void color(const Colori& v) { coloris().append(v); }

	/// Append color to color buffer
	void color(const HSV& v) { colors().append(v); }

	/// Append color to color buffer
	void color(float r, float g, float b, float a=1){ color(Color(r,g,b,a)); }
	
	/// Append color to color buffer
	template <class T>
	void color(const Vec<4,T>& v) { color(v[0], v[1], v[2], v[3]); }

	/// Append floating-point color to integer color buffer
	void colori(const Color& v) { coloris().append(Colori(v)); }


{'fraction_non_alphanumeric': 0.1008339071226379, 'fraction_numerical': 0.010404712722821513, 'mean_word_length': 3.9365558912386707, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3613790', 'n_tokens_mistral': 4261, 'n_tokens_neox': 3893, 'n_words': 1585}