@@ -4078,9 +4078,11 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap) const
40784078			: Base(_vertices, _camera, _depthMap) {}
40794079	};
40804080	RasterMesh rasterer (vertices, camera, depthMap);
4081+ 	RasterMesh::Triangle triangle;
4082+ 	RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
40814083	rasterer.Clear ();
40824084	for  (const  Face& facet: faces)
4083- 		rasterer.Project (facet);
4085+ 		rasterer.Project (facet, triangleRasterizer );
40844086}
40854087void  Mesh::Project (const  Camera& camera, DepthMap& depthMap, Image8U3& image) const 
40864088{
@@ -4097,9 +4099,9 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap, Image8U3& image) co
40974099			Base::Clear ();
40984100			image.memset (0 );
40994101		}
4100- 		void  Raster (const  ImageRef& pt, const  Point3f& bary) {
4101- 			const  Point3f pbary (PerspectiveCorrectBarycentricCoordinates (bary));
4102- 			const  Depth z (ComputeDepth (pbary));
4102+ 		void  Raster (const  ImageRef& pt, const  Triangle& t,  const   Point3f& bary) {
4103+ 			const  Point3f pbary (PerspectiveCorrectBarycentricCoordinates (t,  bary));
4104+ 			const  Depth z (ComputeDepth (t,  pbary));
41034105			ASSERT (z > Depth (0 ));
41044106			Depth& depth = depthMap (pt);
41054107			if  (depth == 0  || depth > z) {
@@ -4115,11 +4117,13 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap, Image8U3& image) co
41154117	if  (image.size () != depthMap.size ())
41164118		image.create (depthMap.size ());
41174119	RasterMesh rasterer (*this , camera, depthMap, image);
4120+ 	RasterMesh::Triangle triangle;
4121+ 	RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
41184122	rasterer.Clear ();
41194123	FOREACH (idxFace, faces) {
41204124		const  Face& facet = faces[idxFace];
41214125		rasterer.idxFaceTex  = idxFace*3 ;
4122- 		rasterer.Project (facet);
4126+ 		rasterer.Project (facet, triangleRasterizer );
41234127	}
41244128}
41254129//  project mesh to the given camera plane, computing also the normal-map (in camera space)
@@ -4138,13 +4142,13 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap, NormalMap& normalMa
41384142			Base::Clear ();
41394143			normalMap.memset (0 );
41404144		}
4141- 		inline  void  Project (const  Face& facet) {
4145+ 		inline  void  Project (const  Face& facet, TriangleRasterizer& tr ) {
41424146			idxVerts = facet.ptr ();
4143- 			Base::Project (facet);
4147+ 			Base::Project (facet, tr );
41444148		}
4145- 		void  Raster (const  ImageRef& pt, const  Point3f& bary) {
4146- 			const  Point3f pbary (PerspectiveCorrectBarycentricCoordinates (bary));
4147- 			const  Depth z (ComputeDepth (pbary));
4149+ 		void  Raster (const  ImageRef& pt, const  Triangle& t,  const   Point3f& bary) {
4150+ 			const  Point3f pbary (PerspectiveCorrectBarycentricCoordinates (t,  bary));
4151+ 			const  Depth z (ComputeDepth (t,  pbary));
41484152			ASSERT (z > Depth (0 ));
41494153			Depth& depth = depthMap (pt);
41504154			if  (depth == Depth (0 ) || depth > z) {
@@ -4160,10 +4164,12 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap, NormalMap& normalMa
41604164	if  (normalMap.size () != depthMap.size ())
41614165		normalMap.create (depthMap.size ());
41624166	RasterMesh rasterer (*this , camera, depthMap, normalMap);
4167+ 	RasterMesh::Triangle triangle;
4168+ 	RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
41634169	rasterer.Clear ();
41644170	//  render the entire mesh
41654171	for  (const  Face& facet: faces)
4166- 		rasterer.Project (facet);
4172+ 		rasterer.Project (facet, triangleRasterizer );
41674173}
41684174//  project mesh to the given camera plane using orthographic projection
41694175void  Mesh::ProjectOrtho (const  Camera& camera, DepthMap& depthMap) const 
@@ -4172,22 +4178,24 @@ void Mesh::ProjectOrtho(const Camera& camera, DepthMap& depthMap) const
41724178		typedef  TRasterMesh<RasterMesh> Base;
41734179		RasterMesh (const  VertexArr& _vertices, const  Camera& _camera, DepthMap& _depthMap)
41744180			: Base(_vertices, _camera, _depthMap) {}
4175- 		inline  bool  ProjectVertex (const  Mesh::Vertex& pt, int  v) {
4176- 			return  (ptc[v] = camera.TransformPointW2C (Cast<REAL>(pt))).z  > 0  &&
4177- 				depthMap.isInsideWithBorder <float ,3 >(pti[v] = camera.TransformPointOrthoC2I (ptc[v]));
4181+ 		inline  bool  ProjectVertex (const  Mesh::Vertex& pt, int  v, Triangle& t ) {
4182+ 			return  (t. ptc [v] = camera.TransformPointW2C (Cast<REAL>(pt))).z  > 0  &&
4183+ 				depthMap.isInsideWithBorder <float ,3 >(t. pti [v] = camera.TransformPointOrthoC2I (t. ptc [v]));
41784184		}
4179- 		void  Raster (const  ImageRef& pt, const  Point3f& bary) {
4180- 			const  Depth z (ComputeDepth (bary));
4185+ 		void  Raster (const  ImageRef& pt, const  Triangle& t,  const   Point3f& bary) {
4186+ 			const  Depth z (ComputeDepth (t,  bary));
41814187			ASSERT (z > Depth (0 ));
41824188			Depth& depth = depthMap (pt);
41834189			if  (depth == 0  || depth > z)
41844190				depth = z;
41854191		}
41864192	};
41874193	RasterMesh rasterer (vertices, camera, depthMap);
4194+ 	RasterMesh::Triangle triangle;
4195+ 	RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
41884196	rasterer.Clear ();
41894197	for  (const  Face& facet: faces)
4190- 		rasterer.Project (facet);
4198+ 		rasterer.Project (facet, triangleRasterizer );
41914199}
41924200void  Mesh::ProjectOrtho (const  Camera& camera, DepthMap& depthMap, Image8U3& image) const 
41934201{
@@ -4204,12 +4212,12 @@ void Mesh::ProjectOrtho(const Camera& camera, DepthMap& depthMap, Image8U3& imag
42044212			Base::Clear ();
42054213			image.memset (0 );
42064214		}
4207- 		inline  bool  ProjectVertex (const  Mesh::Vertex& pt, int  v) {
4208- 			return  (ptc[v] = camera.TransformPointW2C (Cast<REAL>(pt))).z  > 0  &&
4209- 				depthMap.isInsideWithBorder <float ,3 >(pti[v] = camera.TransformPointOrthoC2I (ptc[v]));
4215+ 		inline  bool  ProjectVertex (const  Mesh::Vertex& pt, int  v, Triangle& t ) {
4216+ 			return  (t. ptc [v] = camera.TransformPointW2C (Cast<REAL>(pt))).z  > 0  &&
4217+ 				depthMap.isInsideWithBorder <float ,3 >(t. pti [v] = camera.TransformPointOrthoC2I (t. ptc [v]));
42104218		}
4211- 		void  Raster (const  ImageRef& pt, const  Point3f& bary) {
4212- 			const  Depth z (ComputeDepth (bary));
4219+ 		void  Raster (const  ImageRef& pt, const  Triangle& t,  const   Point3f& bary) {
4220+ 			const  Depth z (ComputeDepth (t,  bary));
42134221			ASSERT (z > Depth (0 ));
42144222			Depth& depth = depthMap (pt);
42154223			if  (depth == 0  || depth > z) {
@@ -4225,11 +4233,13 @@ void Mesh::ProjectOrtho(const Camera& camera, DepthMap& depthMap, Image8U3& imag
42254233	if  (image.size () != depthMap.size ())
42264234		image.create (depthMap.size ());
42274235	RasterMesh rasterer (*this , camera, depthMap, image);
4236+ 	RasterMesh::Triangle triangle;
4237+ 	RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
42284238	rasterer.Clear ();
42294239	FOREACH (idxFace, faces) {
42304240		const  Face& facet = faces[idxFace];
42314241		rasterer.idxFaceTex  = idxFace*3 ;
4232- 		rasterer.Project (facet);
4242+ 		rasterer.Project (facet, triangleRasterizer );
42334243	}
42344244}
42354245//  assuming the mesh is properly oriented, ortho-project it to a camera looking from top to down
0 commit comments