HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_GEOPrimCollect.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GT_GEOPrimCollect.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_GEOPrimCollect__
12 #define __GT_GEOPrimCollect__
13 
14 #include "GT_API.h"
15 #include "GT_Primitive.h"
16 #include "GT_GEODetailList.h"
17 #include "GT_GEOSupport.h"
18 #include <UT/UT_SharedPtr.h>
19 #include <UT/UT_Assert.h>
20 
21 class GT_RefineParms;
22 
23 /// Collection data container.
25 {
26 public:
28  virtual ~GT_GEOPrimCollectData();
29 
30  template <typename T> T *asPointer()
31  {
32  return UTverify_cast<T *>(this);
33  }
34 };
35 
36 /// Collection data container to store primitive offsets
38 {
39 public:
41  ~GT_GEOPrimCollectOffsets() override;
42 
43  virtual void append(const GA_Primitive *prim);
45  { return myPrimitives; }
46 private:
47  GT_GEOOffsetList myPrimitives;
48 };
49 
52 /// Refine primitives for a detail.
53 ///
54 /// When a detail refines itself, it asks the "collectors" to refine
55 /// primitives. The refiners can "collect" primitives on the fly, or they can
56 /// collect primitives and generate a single primitive at the end of the
57 /// collection.
59 {
60 public:
61  /// Constructor
63  /// Destructor
64  virtual ~GT_GEOPrimCollect();
65 
66  /// This method is called when the detail begins collecting. The method
67  /// may or may not be called if there are now collectable primitives in the
68  /// detail.
69  ///
70  /// The data container is passed to the @c collect() and @c endCollect()
71  /// methods. It is automatically deleted on completion. If no data is
72  /// needed for collection, this method should return a NULL pointer (which
73  /// is the default behaviour).
74  virtual GT_GEOPrimCollectData *
75  beginCollecting(const GT_GEODetailListHandle &geometry,
76  const GT_RefineParms *parms) const;
77 
78  /// For each matching primitive in the detail, this method will be called.
79  /// If no GT primitive should be created, return an empty handle.
80  virtual GT_PrimitiveHandle
81  collect(const GT_GEODetailListHandle &geometry,
82  const GEO_Primitive *const* prim_list,
83  int nsegments,
84  GT_GEOPrimCollectData *data) const = 0;
85 
86  /// Complete any processing fter all primitives have been collected
87  ///
88  /// This method should @b not delete the collection data
89  virtual GT_PrimitiveHandle
90  endCollecting(const GT_GEODetailListHandle &geometry,
91  GT_GEOPrimCollectData *data) const;
92 
93  /// Register to process primitives of the given primitive id.
94  /// You can bind to multiple primitive types, in which case,
95  /// @c beginCollecting() and @c endCollecting() will be invoked only once
96  /// for each detail traversal. @c collect() will be called for each
97  /// primitive that matches any of the bound primitive types.
98  /// For example: @code
99  /// gt_GEOPrimQuadricCollect *q = new gt_GEOPrimQuadricCollect();
100  /// q->bind(GA_PrimitiveType(GA_PRIMCIRCLE));
101  /// q->bind(GA_PrimitiveType(GA_PRIMSPHERE));
102  /// q->bind(GA_PrimitiveType(GA_PRIMTUBE));
103  /// @endcode
104  void bind(const GA_PrimitiveTypeId &id) const;
105 
106  /// Get the current collector bound for a primitive
107  static GT_GEOPrimCollectPtr getCollector(const GA_PrimitiveTypeId &id);
108 };
109 
110 #endif
UT_SharedPtr< GT_GEOPrimCollect > GT_GEOPrimCollectPtr
#define GT_API
Definition: GT_API.h:13
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
Collection data container.
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
Collection data container to store primitive offsets.
UT_SharedPtr< GT_GEODetailList > GT_GEODetailListHandle
const GT_GEOOffsetList & getPrimitives() const
Definition: format.h:895