<commit_before>/*
 * trianglemesh.h
 *
 *  Created on: 2017年1月6日
 *      Author: zhuqian
 */

#ifndef SRC_SHAPES_TRIANGLEMESH_H_
#define SRC_SHAPES_TRIANGLEMESH_H_
#include "raiden.h"
#include "shape.h"

//三角Mesh
struct TriangleMesh {
	const int numTriangles;//三角面片的个数
	const int numVertices; //顶点个数
	std::vector<int> vertexIndices;//索引
	std::unique_ptr<Point3f[]> vertices;//顶点数据
	std::unique_ptr<Normal3f[]> normals; //逐顶点法线
	std::unique_ptr<Vector3f[]> tangents; //切线
	std::unique_ptr<Point2f[]> uv; //纹理坐标

	TriangleMesh(const Transform& ObjectToWorld, int nTriangles/*三角面片个数*/,const int* vertexIndices/*顶点索引*/, 
		int nVertices/*顶点个数*/, const Point3f* P/*顶点数组*/, const Vector3f *S/*切线数组*/, const Normal3f *N/*法线数组*/, const Point2f *uv/*纹理坐标数组*/);
};



#endif /* SRC_SHAPES_TRIANGLEMESH_H_ */<commit_msg>add Triangle<commit_after>/*
 * trianglemesh.h
 *
 *  Created on: 2017年1月6日
 *      Author: zhuqian
 */

#ifndef SRC_SHAPES_TRIANGLEMESH_H_
#define SRC_SHAPES_TRIANGLEMESH_H_
#include "raiden.h"
#include "shape.h"

//三角Mesh
struct TriangleMesh {
	const int numTriangles; //三角面片的个数
	const int numVertices; //顶点个数
	std::vector<int> vertexIndices; //索引
	std::unique_ptr<Point3f[]> vertices; //顶点数据
	std::unique_ptr<Normal3f[]> normals; //逐顶点法线
	std::unique_ptr<Vector3f[]> tangents; //切线
	std::unique_ptr<Point2f[]> uv; //纹理坐标

	TriangleMesh(const Transform& ObjectToWorld, int nTriangles/*三角面片个数*/,
			const int* vertexIndices/*顶点索引*/, int nVertices/*顶点个数*/,
			const Point3f* P/*顶点数组*/, const Vector3f *S/*切线数组*/,
			const Normal3f *N/*法线数组*/, const Point2f *uv/*纹理坐标数组*/);
};

//代表一个三角形
class Triangle: public Shape {
private:
	std::shared_ptr<TriangleMesh> _mesh;
	const int * _vertexIndices;
public:
	Triangle(const Transform* ObjectToWorld, const Transform* WorldToObject,
			bool reverseOrientation, std::shared_ptr<TriangleMesh>& mesh,
			int triangleNumber) :
			Shape(ObjectToWorld, WorldToObject, reverseOrientation), _mesh(mesh) {
		_vertexIndices = &(_mesh->vertexIndices[triangleNumber * 3]);
	}
	Bound3f ObjectBound() const override {
		const Point3f& p0 = (*worldToObject)(_mesh->vertices[_vertexIndices[0]]);
		const Point3f& p1 = (*worldToObject)(_mesh->vertices[_vertexIndices[1]]);
		const Point3f& p2 = (*worldToObject)(_mesh->vertices[_vertexIndices[2]]);
		return Union(Bound3f(p0, p1), p2);
	}
	Bound3f WorldBound() const override {
		const Point3f& p0 = _mesh->vertices[_vertexIndices[0]];
		const Point3f& p1 = _mesh->vertices[_vertexIndices[1]];
		const Point3f& p2 = _mesh->vertices[_vertexIndices[2]];
		return Union(Bound3f(p0, p1), p2);
	}
	//三角形的面积
	Float Area() const override{
		Vector3f l1=_mesh->vertices[_vertexIndices[1]]-_mesh->vertices[_vertexIndices[0]];
		Vector3f l2=_mesh->vertices[_vertexIndices[2]]-_mesh->vertices[_vertexIndices[0]];
		return Cross(l1,l2).Length()*0.5f;
	}
};

#endif /* SRC_SHAPES_TRIANGLEMESH_H_ */
{'fraction_non_alphanumeric': 0.15261324041811847, 'fraction_numerical': 0.024041811846689895, 'mean_word_length': 5.480812641083522, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 26, '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': '6169227', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1240, 'n_words': 209}