@@ -4078,9 +4078,11 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap) const
4078
4078
: Base(_vertices, _camera, _depthMap) {}
4079
4079
};
4080
4080
RasterMesh rasterer (vertices, camera, depthMap);
4081
+ RasterMesh::Triangle triangle;
4082
+ RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
4081
4083
rasterer.Clear ();
4082
4084
for (const Face& facet: faces)
4083
- rasterer.Project (facet);
4085
+ rasterer.Project (facet, triangleRasterizer );
4084
4086
}
4085
4087
void Mesh::Project (const Camera& camera, DepthMap& depthMap, Image8U3& image) const
4086
4088
{
@@ -4097,9 +4099,9 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap, Image8U3& image) co
4097
4099
Base::Clear ();
4098
4100
image.memset (0 );
4099
4101
}
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));
4103
4105
ASSERT (z > Depth (0 ));
4104
4106
Depth& depth = depthMap (pt);
4105
4107
if (depth == 0 || depth > z) {
@@ -4115,11 +4117,13 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap, Image8U3& image) co
4115
4117
if (image.size () != depthMap.size ())
4116
4118
image.create (depthMap.size ());
4117
4119
RasterMesh rasterer (*this , camera, depthMap, image);
4120
+ RasterMesh::Triangle triangle;
4121
+ RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
4118
4122
rasterer.Clear ();
4119
4123
FOREACH (idxFace, faces) {
4120
4124
const Face& facet = faces[idxFace];
4121
4125
rasterer.idxFaceTex = idxFace*3 ;
4122
- rasterer.Project (facet);
4126
+ rasterer.Project (facet, triangleRasterizer );
4123
4127
}
4124
4128
}
4125
4129
// 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
4138
4142
Base::Clear ();
4139
4143
normalMap.memset (0 );
4140
4144
}
4141
- inline void Project (const Face& facet) {
4145
+ inline void Project (const Face& facet, TriangleRasterizer& tr ) {
4142
4146
idxVerts = facet.ptr ();
4143
- Base::Project (facet);
4147
+ Base::Project (facet, tr );
4144
4148
}
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));
4148
4152
ASSERT (z > Depth (0 ));
4149
4153
Depth& depth = depthMap (pt);
4150
4154
if (depth == Depth (0 ) || depth > z) {
@@ -4160,10 +4164,12 @@ void Mesh::Project(const Camera& camera, DepthMap& depthMap, NormalMap& normalMa
4160
4164
if (normalMap.size () != depthMap.size ())
4161
4165
normalMap.create (depthMap.size ());
4162
4166
RasterMesh rasterer (*this , camera, depthMap, normalMap);
4167
+ RasterMesh::Triangle triangle;
4168
+ RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
4163
4169
rasterer.Clear ();
4164
4170
// render the entire mesh
4165
4171
for (const Face& facet: faces)
4166
- rasterer.Project (facet);
4172
+ rasterer.Project (facet, triangleRasterizer );
4167
4173
}
4168
4174
// project mesh to the given camera plane using orthographic projection
4169
4175
void Mesh::ProjectOrtho (const Camera& camera, DepthMap& depthMap) const
@@ -4172,22 +4178,24 @@ void Mesh::ProjectOrtho(const Camera& camera, DepthMap& depthMap) const
4172
4178
typedef TRasterMesh<RasterMesh> Base;
4173
4179
RasterMesh (const VertexArr& _vertices, const Camera& _camera, DepthMap& _depthMap)
4174
4180
: 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]));
4178
4184
}
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));
4181
4187
ASSERT (z > Depth (0 ));
4182
4188
Depth& depth = depthMap (pt);
4183
4189
if (depth == 0 || depth > z)
4184
4190
depth = z;
4185
4191
}
4186
4192
};
4187
4193
RasterMesh rasterer (vertices, camera, depthMap);
4194
+ RasterMesh::Triangle triangle;
4195
+ RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
4188
4196
rasterer.Clear ();
4189
4197
for (const Face& facet: faces)
4190
- rasterer.Project (facet);
4198
+ rasterer.Project (facet, triangleRasterizer );
4191
4199
}
4192
4200
void Mesh::ProjectOrtho (const Camera& camera, DepthMap& depthMap, Image8U3& image) const
4193
4201
{
@@ -4204,12 +4212,12 @@ void Mesh::ProjectOrtho(const Camera& camera, DepthMap& depthMap, Image8U3& imag
4204
4212
Base::Clear ();
4205
4213
image.memset (0 );
4206
4214
}
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]));
4210
4218
}
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));
4213
4221
ASSERT (z > Depth (0 ));
4214
4222
Depth& depth = depthMap (pt);
4215
4223
if (depth == 0 || depth > z) {
@@ -4225,11 +4233,13 @@ void Mesh::ProjectOrtho(const Camera& camera, DepthMap& depthMap, Image8U3& imag
4225
4233
if (image.size () != depthMap.size ())
4226
4234
image.create (depthMap.size ());
4227
4235
RasterMesh rasterer (*this , camera, depthMap, image);
4236
+ RasterMesh::Triangle triangle;
4237
+ RasterMesh::TriangleRasterizer triangleRasterizer (triangle, rasterer);
4228
4238
rasterer.Clear ();
4229
4239
FOREACH (idxFace, faces) {
4230
4240
const Face& facet = faces[idxFace];
4231
4241
rasterer.idxFaceTex = idxFace*3 ;
4232
- rasterer.Project (facet);
4242
+ rasterer.Project (facet, triangleRasterizer );
4233
4243
}
4234
4244
}
4235
4245
// assuming the mesh is properly oriented, ortho-project it to a camera looking from top to down
0 commit comments