Skip to content

Commit bb4ec15

Browse files
committed
Subdiv: add adaptive option
1 parent fd5ef1b commit bb4ec15

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

include/slg/shapes/subdiv.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ class Camera;
2929

3030
class SubdivShape : public Shape {
3131
public:
32-
SubdivShape(const Camera *camera, luxrays::ExtTriangleMesh *srcMesh,
33-
const u_int maxLevel, const float maxEdgeScreenSize);
32+
SubdivShape(
33+
const Camera *camera,
34+
luxrays::ExtTriangleMesh *srcMesh,
35+
const u_int maxLevel,
36+
const float maxEdgeScreenSize,
37+
const bool adaptive
38+
);
3439
virtual ~SubdivShape();
3540

3641
virtual ShapeType GetType() const { return SUBDIV; }
3742

3843
static float MaxEdgeScreenSize(const Camera *camera, luxrays::ExtTriangleMesh *srcMesh);
3944
static luxrays::ExtTriangleMesh *ApplySubdiv(luxrays::ExtTriangleMesh *srcMesh,
40-
const u_int maxLevel);
45+
const u_int maxLevel, const bool adaptive);
4146

4247
protected:
4348
virtual luxrays::ExtTriangleMesh *RefineImpl(const Scene *scene);

src/slg/scene/parseshapes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,13 @@ ExtTriangleMesh *Scene::CreateShape(const string &shapeName, const Properties &p
266266
const string sourceMeshName = props.Get(Property(propName + ".source")("")).Get<string>();
267267
if (!extMeshCache.IsExtMeshDefined(sourceMeshName))
268268
throw runtime_error("Unknown shape name in a subdiv shape: " + shapeName);
269-
269+
270270
const u_int maxLevel = props.Get(Property(propName + ".maxlevel")(2)).Get<u_int>();
271271
const float maxEdgeScreenSize = Max(props.Get(Property(propName + ".maxedgescreensize")(0.f)).Get<float>(), 0.f);
272+
const bool subdivAdaptive = props.Get(Property(propName + ".adaptive")(true)).Get<bool>();
272273

273274
shape = new SubdivShape(camera, (ExtTriangleMesh *)extMeshCache.GetExtMesh(sourceMeshName),
274-
maxLevel, maxEdgeScreenSize);
275+
maxLevel, maxEdgeScreenSize, subdivAdaptive);
275276
} else if (shapeType == "displacement") {
276277
const string sourceMeshName = props.Get(Property(propName + ".source")("")).Get<string>();
277278
if (!extMeshCache.IsExtMeshDefined(sourceMeshName))

src/slg/shapes/subdiv.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ float SubdivShape::MaxEdgeScreenSize(const Camera *camera, ExtTriangleMesh *srcM
156156

157157
static Far::TopologyRefiner * createFarTopologyRefiner(const ExtTriangleMesh*);
158158

159-
ExtTriangleMesh *SubdivShape::ApplySubdiv(ExtTriangleMesh *srcMesh, const u_int maxLevel) {
159+
ExtTriangleMesh *SubdivShape::ApplySubdiv(
160+
ExtTriangleMesh *srcMesh, const u_int maxLevel, const bool adaptive
161+
) {
160162
//--------------------------------------------------------------------------
161163
// Check data
162164
//--------------------------------------------------------------------------
@@ -174,10 +176,17 @@ ExtTriangleMesh *SubdivShape::ApplySubdiv(ExtTriangleMesh *srcMesh, const u_int
174176
// Set-up refiner
175177
std::unique_ptr<Far::TopologyRefiner> refiner(createFarTopologyRefiner(srcMesh));
176178

177-
// Uniformly refine the topology up to 'maxlevel'
178-
Far::TopologyRefiner::UniformOptions refiner_options(maxLevel);
179-
refiner_options.fullTopologyInLastLevel = true;
180-
refiner->RefineUniform(refiner_options);
179+
// Refine the topology up to 'maxlevel'
180+
if (adaptive) {
181+
SDL_LOG("Subdiv - Refining (adaptive)");
182+
Far::TopologyRefiner::AdaptiveOptions refiner_options(maxLevel);
183+
refiner->RefineAdaptive(refiner_options);
184+
} else {
185+
SDL_LOG("Subdiv - Refining (uniform)");
186+
Far::TopologyRefiner::UniformOptions refiner_options(maxLevel);
187+
refiner_options.fullTopologyInLastLevel = true;
188+
refiner->RefineUniform(refiner_options);
189+
}
181190

182191
Far::TopologyLevel const& refFirstLevel = refiner->GetLevel(0);
183192
Far::TopologyLevel const& refLastLevel = refiner->GetLevel(maxLevel);
@@ -412,7 +421,7 @@ ExtTriangleMesh *SubdivShape::ApplySubdiv(ExtTriangleMesh *srcMesh, const u_int
412421
}
413422

414423
SubdivShape::SubdivShape(const Camera *camera, ExtTriangleMesh *srcMesh,
415-
const u_int maxLevel, const float maxEdgeScreenSize) {
424+
const u_int maxLevel, const float maxEdgeScreenSize, const bool adaptive) {
416425
const double startTime = WallClockTime();
417426

418427
if ((maxEdgeScreenSize > 0.f) && !camera)
@@ -433,7 +442,7 @@ SubdivShape::SubdivShape(const Camera *camera, ExtTriangleMesh *srcMesh,
433442
break;
434443

435444
// Subdivide by one level and re-try
436-
ExtTriangleMesh *newMesh = ApplySubdiv(mesh, 1);
445+
ExtTriangleMesh *newMesh = ApplySubdiv(mesh, 1, adaptive);
437446
SDL_LOG("Subdivided shape step #" << i << " from " << mesh->GetTotalTriangleCount() << " to " << newMesh->GetTotalTriangleCount() << " faces");
438447

439448
// Replace old mesh with new one
@@ -443,7 +452,7 @@ SubdivShape::SubdivShape(const Camera *camera, ExtTriangleMesh *srcMesh,
443452
} else {
444453
SDL_LOG("Subdividing shape " << srcMesh->GetName() << " at level: " << maxLevel);
445454

446-
mesh = ApplySubdiv(srcMesh, maxLevel);
455+
mesh = ApplySubdiv(srcMesh, maxLevel, adaptive);
447456
}
448457
} else {
449458
// Nothing to do, just make a copy

0 commit comments

Comments
 (0)