OpenSubdiv
Loading...
Searching...
No Matches
topologyRefinerFactory.h
Go to the documentation of this file.
1//
2// Copyright 2014 DreamWorks Animation LLC.
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7#ifndef OPENSUBDIV3_FAR_TOPOLOGY_REFINER_FACTORY_H
8#define OPENSUBDIV3_FAR_TOPOLOGY_REFINER_FACTORY_H
9
10#include "../version.h"
11
13#include "../far/error.h"
14
15#include <cassert>
16
17namespace OpenSubdiv {
18namespace OPENSUBDIV_VERSION {
19
20namespace Far {
21
29//
31protected:
32
33 //
34 // Protected methods invoked by the subclass template to verify and process each
35 // stage of construction implemented by the subclass:
36 //
37 typedef Vtr::internal::Level::ValidationCallback TopologyCallback;
38
40 static bool prepareComponentTopologyAssignment(TopologyRefiner& refiner, bool fullValidation,
41 TopologyCallback callback, void const * callbackData);
44};
45
46
60template <class MESH>
62
63public:
64
81
91 //
96 static TopologyRefiner* Create(MESH const& mesh, Options options = Options());
97
111 static TopologyRefiner* Create(TopologyRefiner const & baseLevel);
112
113protected:
114 typedef Vtr::internal::Level::TopologyError TopologyError;
115
117
132
134 static bool resizeComponentTopology(TopologyRefiner& newRefiner, MESH const& mesh);
135
138 static bool assignComponentTopology(TopologyRefiner& newRefiner, MESH const& mesh);
139
141 static bool assignComponentTags(TopologyRefiner& newRefiner, MESH const& mesh);
142
144 static bool assignFaceVaryingTopology(TopologyRefiner& newRefiner, MESH const& mesh);
145
147 static void reportInvalidTopology(TopologyError errCode, char const * msg, MESH const& mesh);
148
150
151protected:
153
170
172 static void setNumBaseVertices(TopologyRefiner & newRefiner, int count);
173
175 static void setNumBaseFaces(TopologyRefiner & newRefiner, int count);
176
178 static void setNumBaseEdges(TopologyRefiner & newRefiner, int count);
179
181 static void setNumBaseFaceVertices(TopologyRefiner & newRefiner, Index f, int count);
182
184 static void setNumBaseEdgeFaces(TopologyRefiner & newRefiner, Index e, int count);
185
187 static void setNumBaseVertexFaces(TopologyRefiner & newRefiner, Index v, int count);
188
190 static void setNumBaseVertexEdges(TopologyRefiner & newRefiner, Index v, int count);
191
192 static int getNumBaseVertices(TopologyRefiner const & newRefiner);
193 static int getNumBaseFaces(TopologyRefiner const & newRefiner);
194 static int getNumBaseEdges(TopologyRefiner const & newRefiner);
196
198
220
222 static IndexArray getBaseFaceVertices(TopologyRefiner & newRefiner, Index f);
223
225 static IndexArray getBaseFaceEdges(TopologyRefiner & newRefiner, Index f);
226
228 static IndexArray getBaseEdgeVertices(TopologyRefiner & newRefiner, Index e);
229
231 static IndexArray getBaseEdgeFaces(TopologyRefiner & newRefiner, Index e);
232
234 static IndexArray getBaseVertexFaces(TopologyRefiner & newRefiner, Index v);
235
237 static IndexArray getBaseVertexEdges(TopologyRefiner & newRefiner, Index v);
238
245
247 static void populateBaseLocalIndices(TopologyRefiner & newRefiner);
248
250 static void setBaseEdgeNonManifold(TopologyRefiner & newRefiner, Index e, bool b);
251
253 static void setBaseVertexNonManifold(TopologyRefiner & newRefiner, Index v, bool b);
255
257
266
268 static Index findBaseEdge(TopologyRefiner const & newRefiner, Index v0, Index v1);
269
271 static void setBaseEdgeSharpness(TopologyRefiner & newRefiner, Index e, float sharpness);
272
274 static void setBaseVertexSharpness(TopologyRefiner & newRefiner, Index v, float sharpness);
275
277 static void setBaseFaceHole(TopologyRefiner & newRefiner, Index f, bool isHole);
279
281
291
293 static int createBaseFVarChannel(TopologyRefiner & newRefiner, int numValues);
294
296 static int createBaseFVarChannel(TopologyRefiner & newRefiner, int numValues, Sdc::Options const& fvarOptions);
297
299 static IndexArray getBaseFaceFVarValues(TopologyRefiner & newRefiner, Index face, int channel = 0);
300
302
303protected:
304 //
305 // Not to be specialized:
306 //
307 static bool populateBaseLevel(TopologyRefiner& refiner, MESH const& mesh, Options options);
308
309private:
310 //
311 // An oversight in the interfaces of the error reporting function between the factory
312 // class and the Vtr::Level requires this adapter function to avoid warnings.
313 //
314 // The static class method requires a reference as the MESH argument, but the interface
315 // for Vtr::Level requires a pointer (void*). So this adapter with a MESH* argument is
316 // used to effectively cast the function pointer required by Vtr::Level error reporting:
317 //
318 static void reportInvalidTopologyAdapter(TopologyError errCode, char const * msg, MESH const * mesh) {
319 reportInvalidTopology(errCode, msg, *mesh);
320 }
321};
322
323
324//
325// Generic implementations:
326//
327template <class MESH>
328TopologyRefiner*
330
331 TopologyRefiner * refiner = new TopologyRefiner(options.schemeType, options.schemeOptions);
332
333 if (! populateBaseLevel(*refiner, mesh, options)) {
334 delete refiner;
335 return 0;
336 }
337
338 // Eventually want to move the Refiner's inventory initialization here. Currently it
339 // is handled after topology assignment, but if the inventory is to include additional
340 // features (e.g. holes, etc.) it is better off deferred to here.
341
342 return refiner;
343}
344
345template <class MESH>
348
349 return new TopologyRefiner(source);
350}
351
352template <class MESH>
353bool
355
356 //
357 // Construction of a specialized topology refiner involves four steps, each of which
358 // involves a method specialized for MESH followed by one that takes an action in
359 // response to it or in preparation for the next step.
360 //
361 // Both the specialized methods and those that follow them may find fault in the
362 // construction and trigger failure at any time:
363 //
364
365 //
366 // Sizing of the topology -- this is a required specialization for MESH. This defines
367 // an inventory of all components and their relations that is used to allocate buffers
368 // to be efficiently populated in the subsequent topology assignment step.
369 //
370 if (! resizeComponentTopology(refiner, mesh)) return false;
371 if (! prepareComponentTopologySizing(refiner)) return false;
372
373 //
374 // Assignment of the topology -- this is a required specialization for MESH. If edges
375 // are specified, all other topological relations are expected to be defined for them.
376 // Otherwise edges and remaining topology will be completed from the face-vertices:
377 //
378 bool validate = options.validateFullTopology;
379 TopologyCallback callback = reinterpret_cast<TopologyCallback>(reportInvalidTopologyAdapter);
380 void const * userData = &mesh;
381
382 if (! assignComponentTopology(refiner, mesh)) return false;
383 if (! prepareComponentTopologyAssignment(refiner, validate, callback, userData)) return false;
384
385 //
386 // User assigned and internal tagging of components -- an optional specialization for
387 // MESH. Allows the specification of sharpness values, holes, etc.
388 //
389 if (! assignComponentTags(refiner, mesh)) return false;
390 if (! prepareComponentTagsAndSharpness(refiner)) return false;
391
392 //
393 // Defining channels of face-varying primvar data -- an optional specialization for MESH.
394 //
395 if (! assignFaceVaryingTopology(refiner, mesh)) return false;
396 if (! prepareFaceVaryingChannels(refiner)) return false;
397
398 return true;
399}
400
401template <class MESH>
402inline void
404 newRefiner._levels[0]->resizeFaces(count);
405}
406template <class MESH>
407inline void
409 newRefiner._levels[0]->resizeEdges(count);
410}
411template <class MESH>
412inline void
414 newRefiner._levels[0]->resizeVertices(count);
415}
416
417template <class MESH>
418inline int
420 return newRefiner._levels[0]->getNumFaces();
421}
422template <class MESH>
423inline int
425 return newRefiner._levels[0]->getNumEdges();
426}
427template <class MESH>
428inline int
430 return newRefiner._levels[0]->getNumVertices();
431}
432
433template <class MESH>
434inline void
436 newRefiner._levels[0]->resizeFaceVertices(f, count);
437 newRefiner._hasIrregFaces = newRefiner._hasIrregFaces || (count != newRefiner._regFaceSize);
438}
439template <class MESH>
440inline void
442 newRefiner._levels[0]->resizeEdgeFaces(e, count);
443}
444template <class MESH>
445inline void
447 newRefiner._levels[0]->resizeVertexFaces(v, count);
448}
449template <class MESH>
450inline void
452 newRefiner._levels[0]->resizeVertexEdges(v, count);
453}
454
455template <class MESH>
456inline IndexArray
458 return newRefiner._levels[0]->getFaceVertices(f);
459}
460template <class MESH>
461inline IndexArray
463 return newRefiner._levels[0]->getFaceEdges(f);
464}
465template <class MESH>
466inline IndexArray
468 return newRefiner._levels[0]->getEdgeVertices(e);
469}
470template <class MESH>
471inline IndexArray
473 return newRefiner._levels[0]->getEdgeFaces(e);
474}
475template <class MESH>
476inline IndexArray
478 return newRefiner._levels[0]->getVertexFaces(v);
479}
480template <class MESH>
481inline IndexArray
483 return newRefiner._levels[0]->getVertexEdges(v);
484}
485
486template <class MESH>
487inline LocalIndexArray
489 return newRefiner._levels[0]->getEdgeFaceLocalIndices(e);
490}
491template <class MESH>
492inline LocalIndexArray
494 return newRefiner._levels[0]->getVertexFaceLocalIndices(v);
495}
496template <class MESH>
497inline LocalIndexArray
499 return newRefiner._levels[0]->getVertexEdgeLocalIndices(v);
500}
501
502template <class MESH>
503inline Index
505 return newRefiner._levels[0]->findEdge(v0, v1);
506}
507
508template <class MESH>
509inline void
511 newRefiner._levels[0]->populateLocalIndices();
512}
513
514template <class MESH>
515inline void
517 newRefiner._levels[0]->setEdgeNonManifold(e, b);
518}
519template <class MESH>
520inline void
522 newRefiner._levels[0]->setVertexNonManifold(v, b);
523}
524
525template <class MESH>
526inline void
528 newRefiner._levels[0]->getEdgeSharpness(e) = s;
529}
530template <class MESH>
531inline void
533 newRefiner._levels[0]->getVertexSharpness(v) = s;
534}
535template <class MESH>
536inline void
538 newRefiner._levels[0]->setFaceHole(f, b);
539 newRefiner._hasHoles = newRefiner._hasHoles || b;
540}
541
542template <class MESH>
543inline int
545 return newRefiner._levels[0]->createFVarChannel(numValues, newRefiner._subdivOptions);
546}
547template <class MESH>
548inline int
550 Sdc::Options newOptions = newRefiner._subdivOptions;
552 return newRefiner._levels[0]->createFVarChannel(numValues, newOptions);
553}
554template <class MESH>
555inline IndexArray
557 return newRefiner._levels[0]->getFaceFVarValues(face, channel);
558}
559
560
561template <class MESH>
562bool
564
566 "Failure in TopologyRefinerFactory<>::resizeComponentTopology() -- no specialization provided.");
567
568 //
569 // Sizing the topology tables:
570 // This method is for determining the sizes of the various topology tables (and other
571 // data) associated with the mesh. Once completed, appropriate memory will be allocated
572 // and an additional method invoked to populate it accordingly.
573 //
574 // The following methods should be called -- first those to specify the number of faces,
575 // edges and vertices in the mesh:
576 //
577 // void setBaseFaceCount( TopologyRefiner& newRefiner, int count)
578 // void setBaseEdgeCount( TopologyRefiner& newRefiner, int count)
579 // void setBaseVertexCount(TopologyRefiner& newRefiner, int count)
580 //
581 // and then for each face, edge and vertex, the number of its incident components:
582 //
583 // void setBaseFaceVertexCount(TopologyRefiner& newRefiner, Index face, int count)
584 // void setBaseEdgeFaceCount( TopologyRefiner& newRefiner, Index edge, int count)
585 // void setBaseVertexFaceCount(TopologyRefiner& newRefiner, Index vertex, int count)
586 // void setBaseVertexEdgeCount(TopologyRefiner& newRefiner, Index vertex, int count)
587 //
588 // The count/size for a component type must be set before indices associated with that
589 // component type can be used.
590 //
591 // Note that it is only necessary to size 4 of the 6 supported topological relations --
592 // the number of edge-vertices is fixed at two per edge, and the number of face-edges is
593 // the same as the number of face-vertices.
594 //
595 // So a single pass through your mesh to gather up all of this sizing information will
596 // allow the Tables to be allocated appropriately once and avoid any dynamic resizing as
597 // it grows.
598 //
599 return false;
600}
601
602template <class MESH>
603bool
605
607 "Failure in TopologyRefinerFactory<>::assignComponentTopology() -- no specialization provided.");
608
609 //
610 // Assigning the topology tables:
611 // Once the topology tables have been allocated, the six required topological
612 // relations can be directly populated using the following methods:
613 //
614 // IndexArray setBaseFaceVertices(TopologyRefiner& newRefiner, Index face)
615 // IndexArray setBaseFaceEdges(TopologyRefiner& newRefiner, Index face)
616 //
617 // IndexArray setBaseEdgeVertices(TopologyRefiner& newRefiner, Index edge)
618 // IndexArray setBaseEdgeFaces(TopologyRefiner& newRefiner, Index edge)
619 //
620 // IndexArray setBaseVertexEdges(TopologyRefiner& newRefiner, Index vertex)
621 // IndexArray setBaseVertexFaces(TopologyRefiner& newRefiner, Index vertex)
622 //
623 // For the last two relations -- the faces and edges incident a vertex -- there are
624 // also "local indices" that must be specified (considering doing this internally),
625 // where the "local index" of each incident face or edge is the index of the vertex
626 // within that face or edge, and so ranging from 0-3 for incident quads and 0-1 for
627 // incident edges. These are assigned through similarly retrieved arrays:
628 //
629 // LocalIndexArray setBaseVertexFaceLocalIndices(TopologyRefiner& newRefiner, Index vertex)
630 // LocalIndexArray setBaseVertexEdgeLocalIndices(TopologyRefiner& newRefiner, Index vertex)
631 // LocalIndexArray setBaseEdgeFaceLocalIndices( TopologyRefiner& newRefiner, Index edge)
632 //
633 // or, if the mesh is manifold, explicit assignment of these can be deferred and
634 // all can be determined by calling:
635 //
636 // void populateBaseLocalIndices(TopologyRefiner& newRefiner)
637 //
638 // All components are assumed to be locally manifold and ordering of components in
639 // the above relations is expected to be counter-clockwise.
640 //
641 // For non-manifold components, no ordering/orientation of incident components is
642 // assumed or required, but be sure to explicitly tag such components (vertices and
643 // edges) as non-manifold:
644 //
645 // void setBaseEdgeNonManifold(TopologyRefiner& newRefiner, Index edge, bool b);
646 //
647 // void setBaseVertexNonManifold(TopologyRefiner& newRefiner, Index vertex, bool b);
648 //
649 // Also consider using TopologyLevel::ValidateTopology() when debugging to ensure
650 // that topology has been completely and correctly specified.
651 //
652 return false;
653}
654
655template <class MESH>
656bool
658
659 //
660 // Optional assigning face-varying topology tables:
661 //
662 // Create independent face-varying primitive variable channels:
663 // int createBaseFVarChannel(TopologyRefiner& newRefiner, int numValues)
664 //
665 // For each channel, populate the face-vertex values:
666 // IndexArray setBaseFaceFVarValues(TopologyRefiner& newRefiner, Index face, int channel = 0)
667 //
668 return true;
669}
670
671template <class MESH>
672bool
674
675 //
676 // Optional tagging:
677 // This is where any additional feature tags -- sharpness, holes, etc. -- can be
678 // specified using:
679 //
680 // void setBaseEdgeSharpness(TopologyRefiner& newRefiner, Index edge, float sharpness)
681 // void setBaseVertexSharpness(TopologyRefiner& newRefiner, Index vertex, float sharpness)
682 //
683 // void setBaseFaceHole(TopologyRefiner& newRefiner, Index face, bool hole)
684 //
685 return true;
686}
687
688template <class MESH>
689void
691 TopologyError /* errCode */, char const * /* msg */, MESH const& /* mesh */) {
692
693 //
694 // Optional topology validation error reporting:
695 // This method is called whenever the factory encounters topology validation
696 // errors. By default, nothing is reported
697 //
698}
699
700} // end namespace Far
701
702} // end namespace OPENSUBDIV_VERSION
703using namespace OPENSUBDIV_VERSION;
704} // end namespace OpenSubdiv
705
706#endif /* OPENSUBDIV3_FAR_TOPOLOGY_REFINER_FACTORY_H */
void Error(ErrorType err, const char *format,...)
Sends an OSD error with a message (internal use only)
@ FAR_RUNTIME_ERROR
Issue a generic runtime error, but continue execution.
Definition error.h:23
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition types.h:20
Factory for constructing TopologyRefiners from specific mesh classes.
static int getNumBaseFaces(TopologyRefiner const &newRefiner)
static bool assignComponentTopology(TopologyRefiner &newRefiner, MESH const &mesh)
Specify the relationships between vertices, faces, etc. ie the face-vertices, vertex-faces,...
static void reportInvalidTopology(TopologyError errCode, char const *msg, MESH const &mesh)
(Optional) Control run-time topology validation and error reporting
static LocalIndexArray getBaseVertexFaceLocalIndices(TopologyRefiner &newRefiner, Index v)
Assign the local indices of a vertex within each of its incident faces.
static int getNumBaseVertices(TopologyRefiner const &newRefiner)
static void setNumBaseEdgeFaces(TopologyRefiner &newRefiner, Index e, int count)
Specify the number of faces incident each edge.
static IndexArray getBaseFaceVertices(TopologyRefiner &newRefiner, Index f)
Assign the vertices incident each face.
static LocalIndexArray getBaseEdgeFaceLocalIndices(TopologyRefiner &newRefiner, Index e)
Assign the local indices of an edge within each of its incident faces.
static bool populateBaseLevel(TopologyRefiner &refiner, MESH const &mesh, Options options)
static void populateBaseLocalIndices(TopologyRefiner &newRefiner)
Determine all local indices by inspection (only for pure manifold meshes)
static bool assignComponentTags(TopologyRefiner &newRefiner, MESH const &mesh)
(Optional) Specify edge or vertex sharpness or face holes
static bool resizeComponentTopology(TopologyRefiner &newRefiner, MESH const &mesh)
Specify the number of vertices, faces, face-vertices, etc.
static void setNumBaseVertexEdges(TopologyRefiner &newRefiner, Index v, int count)
Specify the number of edges incident each vertex.
static IndexArray getBaseFaceFVarValues(TopologyRefiner &newRefiner, Index face, int channel=0)
Assign the face-varying values for the corners of each face.
static IndexArray getBaseEdgeFaces(TopologyRefiner &newRefiner, Index e)
Assign the faces incident each edge.
static void setNumBaseVertexFaces(TopologyRefiner &newRefiner, Index v, int count)
Specify the number of faces incident each vertex.
static bool assignFaceVaryingTopology(TopologyRefiner &newRefiner, MESH const &mesh)
(Optional) Specify face-varying data per face
static void setBaseVertexSharpness(TopologyRefiner &newRefiner, Index v, float sharpness)
Assign a sharpness value to a given vertex.
static LocalIndexArray getBaseVertexEdgeLocalIndices(TopologyRefiner &newRefiner, Index v)
Assign the local indices of a vertex within each of its incident edges.
static IndexArray getBaseEdgeVertices(TopologyRefiner &newRefiner, Index e)
Assign the vertices incident each edge.
static IndexArray getBaseVertexFaces(TopologyRefiner &newRefiner, Index v)
Assign the faces incident each vertex.
static void setBaseVertexNonManifold(TopologyRefiner &newRefiner, Index v, bool b)
Tag a vertex as non-manifold.
static void setNumBaseFaces(TopologyRefiner &newRefiner, int count)
Specify the number of faces to be accommodated.
static IndexArray getBaseFaceEdges(TopologyRefiner &newRefiner, Index f)
Assign the edges incident each face.
static void setNumBaseFaceVertices(TopologyRefiner &newRefiner, Index f, int count)
Specify the number of vertices incident each face.
static void setBaseEdgeSharpness(TopologyRefiner &newRefiner, Index e, float sharpness)
Assign a sharpness value to a given edge.
static void setBaseEdgeNonManifold(TopologyRefiner &newRefiner, Index e, bool b)
Tag an edge as non-manifold.
static void setNumBaseEdges(TopologyRefiner &newRefiner, int count)
Specify the number of edges to be accommodated.
static TopologyRefiner * Create(MESH const &mesh, Options options=Options())
Instantiates a TopologyRefiner from client-provided topological representation.
static Index findBaseEdge(TopologyRefiner const &newRefiner, Index v0, Index v1)
Identify an edge to be assigned a sharpness value given a vertex pair.
static IndexArray getBaseVertexEdges(TopologyRefiner &newRefiner, Index v)
Assign the edges incident each vertex.
static int createBaseFVarChannel(TopologyRefiner &newRefiner, int numValues)
Create a new face-varying channel with the given number of values.
static int getNumBaseEdges(TopologyRefiner const &newRefiner)
static void setNumBaseVertices(TopologyRefiner &newRefiner, int count)
Specify the number of vertices to be accommodated.
static void setBaseFaceHole(TopologyRefiner &newRefiner, Index f, bool isHole)
Tag a face as a hole.
Stores topology data for a specified set of refinement options.
Private base class of Factories for constructing TopologyRefiners.
static bool prepareComponentTopologyAssignment(TopologyRefiner &refiner, bool fullValidation, TopologyCallback callback, void const *callbackData)
static bool prepareComponentTagsAndSharpness(TopologyRefiner &refiner)
static bool prepareComponentTopologySizing(TopologyRefiner &refiner)
static bool prepareFaceVaryingChannels(TopologyRefiner &refiner)
Options related to the construction of each TopologyRefiner.
Options(Sdc::SchemeType sdcType=Sdc::SCHEME_CATMARK, Sdc::Options sdcOptions=Sdc::Options())
Sdc::SchemeType schemeType
The subdivision scheme type identifier.
All supported options applying to subdivision scheme.
Definition options.h:34
void SetFVarLinearInterpolation(FVarLinearInterpolation b)
Set face-varying interpolation rule.
Definition options.h:81
FVarLinearInterpolation GetFVarLinearInterpolation() const
Get face-varying interpolation rule.
Definition options.h:78