1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 /*=========================================================================
19  *
20  *  Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  *  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  *  For complete copyright, license and disclaimer of warranty information
25  *  please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkPointSet_h
29 #define itkPointSet_h
30 
31 #include "itkDataObject.h"
32 #include "itkDefaultStaticMeshTraits.h"
33 #include <vector>
34 #include <set>
35 
36 namespace itk
37 {
38 
39 /** \class PointSet
40  * \brief A superclass of the N-dimensional mesh structure;
41  * supports point (geometric coordinate and attribute) definition.
42  *
43  * PointSet is a superclass of the N-dimensional mesh structure (itk::Mesh).
44  * It provides the portion of the mesh definition for geometric coordinates
45  * (and associated attribute or pixel information). The defined API provides
46  * operations on points but does not tie down the underlying implementation
47  * and storage.  A "MeshTraits" structure is used to define the container
48  * and identifier to access the points.  See DefaultStaticMeshTraits
49  * for the set of type definitions needed.  All types that are defined
50  * in the "MeshTraits" structure will have duplicate type alias in the resulting
51  * mesh itself.
52  *
53  * PointSet has two template parameters.  The first is the pixel type, or the
54  * type of data stored (optionally) with the points.
55  * The second is the "MeshTraits" structure controlling type information
56  * characterizing the point set.  Most users will be happy with the
57  * defaults, and will not have to worry about this second argument.
58  *
59  * Template parameters for PointSet:
60  *
61  * TPixelType =
62  *     The type stored as data for the point.
63  *
64  * TMeshTraits =
65  *     Type information structure for the point set.
66  *
67  * \ingroup MeshObjects
68  * \ingroup DataRepresentation
69  * \ingroup ITKCommon
70  *
71  * \wiki
72  * \wikiexample{PointSet/CreatePointSet,Create a PointSet}
73  * \wikiexample{PointSet/ReadPointSet,Read a PointSet}
74  * \wikiexample{PointSet/WritePointSet,Write a PointSet}
75  * \wikiexample{PointSet/BoundingBox,Get the bounding box of a PointSet}
76  * \endwiki
77  */
78 
79 template<
80   typename TPixelType,
81   unsigned int VDimension = 3,
82   typename TMeshTraits = DefaultStaticMeshTraits< TPixelType, VDimension, VDimension >
83   >
84 class ITK_TEMPLATE_EXPORT PointSet:public DataObject
85 {
86 public:
87   ITK_DISALLOW_COPY_AND_ASSIGN(PointSet);
88 
89   /** Standard class type aliases. */
90   using Self = PointSet;
91   using Superclass = DataObject;
92   using Pointer = SmartPointer< Self >;
93   using ConstPointer = SmartPointer< const Self >;
94 
95   /** Method for creation through the object factory. */
96   itkNewMacro(Self);
97 
98   /** Standard part of every itk Object. */
99   itkTypeMacro(PointSet, Object);
100 
101   /** Hold on to the type information specified by the template parameters. */
102   using MeshTraits = TMeshTraits;
103   using PixelType = typename MeshTraits::PixelType;
104 
105   /** Convenient type alias obtained from TMeshTraits template parameter. */
106   using CoordRepType = typename MeshTraits::CoordRepType;
107   using PointIdentifier = typename MeshTraits::PointIdentifier;
108   using PointType = typename MeshTraits::PointType;
109   using PointsContainer = typename MeshTraits::PointsContainer;
110   using PointDataContainer = typename MeshTraits::PointDataContainer;
111 
112   /** Convenient type alias obtained from TMeshTraits template parameter. */
113   static constexpr unsigned int PointDimension = TMeshTraits::PointDimension;
114 
115   /** Create types that are pointers to each of the container types. */
116   using PointsContainerPointer = typename PointsContainer::Pointer;
117   using PointsContainerConstPointer = typename PointsContainer::ConstPointer;
118   using PointDataContainerPointer = typename PointDataContainer::Pointer;
119   using PointDataContainerConstPointer = typename PointDataContainer::ConstPointer;
120 
121   /** Create types that are iterators for each of the container types. */
122   using PointsContainerConstIterator = typename PointsContainer::ConstIterator;
123   using PointsContainerIterator = typename PointsContainer::Iterator;
124   using PointDataContainerIterator = typename PointDataContainer::ConstIterator;
125 
126   /** Type used to define Regions */
127   using RegionType = long;
128 
129   /** Get the maximum number of regions that this data can be
130    * separated into. */
131   itkGetConstMacro(MaximumNumberOfRegions, RegionType);
132 
133 protected:
134   /** An object containing points used by the mesh.  Individual points are
135    * accessed through point identifiers. */
136   PointsContainerPointer m_PointsContainer;
137 
138   /** An object containing data associated with the mesh's points.
139    * Optionally, this can be nullptr, indicating that no data are associated with
140    * the points.  The data for a point can be accessed through its point
141    * identifier. */
142   PointDataContainerPointer m_PointDataContainer;
143 
144 public:
145   /** PointSet-level operation interface. */
146   void PassStructure(Self *inputPointSet);
147 
148   void Initialize() override;
149 
150   PointIdentifier GetNumberOfPoints() const;
151 
152   /** Define Set/Get access routines for each internal container.
153    * Methods also exist to add points, cells, etc. one at a time
154    * rather than through an entire container. */
155   void SetPoints(PointsContainer *);
156 
157   PointsContainer * GetPoints();
158 
159   const PointsContainer * GetPoints() const;
160 
161   void SetPointData(PointDataContainer *);
162 
163   PointDataContainer * GetPointData();
164 
165   const PointDataContainer * GetPointData() const;
166 
167   /** Access routines to fill the Points container, and get information
168    * from it. */
169   void SetPoint(PointIdentifier, PointType);
170   bool GetPoint(PointIdentifier, PointType *) const;
171   PointType GetPoint(PointIdentifier) const;
172 
173   /** Access routines to fill the PointData container, and get information
174    * from it. */
175   void SetPointData(PointIdentifier, PixelType);
176   bool GetPointData(PointIdentifier, PixelType *) const;
177 
178   /** Methods to manage streaming. */
179   void UpdateOutputInformation() override;
180 
181   void SetRequestedRegionToLargestPossibleRegion() override;
182 
183   void CopyInformation(const DataObject *data) override;
184 
185   void Graft(const DataObject *data) override;
186 
187   bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
188 
189   bool VerifyRequestedRegion() override;
190 
191   /** Set the requested region from this data object to match the requested
192    * region of the data object passed in as a parameter.  This method
193    * implements the API from DataObject. The data object parameter must be
194    * castable to a PointSet. */
195   void SetRequestedRegion(const DataObject *data) override;
196 
197   /** Set/Get the Requested region */
198   virtual void SetRequestedRegion(const RegionType & region);
199 
200   itkGetConstMacro(RequestedRegion, RegionType);
201 
202   /** Set/Get the Buffered region */
203   virtual void SetBufferedRegion(const RegionType & region);
204 
205   itkGetConstMacro(BufferedRegion, RegionType);
206 
207 protected:
208   /** Constructor for use by New() method. */
209   PointSet();
210   ~PointSet() override = default;
211   void PrintSelf(std::ostream & os, Indent indent) const override;
212 
213   // If the RegionType is ITK_UNSTRUCTURED_REGION, then the following
214   // variables represent the maximum number of region that the data
215   // object can be broken into, which region out of how many is
216   // currently in the buffered region, and the number of regions and
217   // the specific region requested for the update. Data objects that
218   // do not support any division of the data can simply leave the
219   // MaximumNumberOfRegions as 1. The RequestedNumberOfRegions and
220   // RequestedRegion are used to define the currently requested
221   // region. The LargestPossibleRegion is always requested region = 0
222   // and number of regions = 1;
223   RegionType m_MaximumNumberOfRegions;
224   RegionType m_NumberOfRegions;
225   RegionType m_RequestedNumberOfRegions;
226   RegionType m_BufferedRegion;
227   RegionType m_RequestedRegion;
228 };                              // End Class: PointSet
229 } // end namespace itk
230 
231 #ifndef ITK_MANUAL_INSTANTIATION
232 #include "itkPointSet.hxx"
233 #endif
234 
235 /*
236 #ifndef ITK_MANUAL_INSTANTIATION
237 #include "itkPointSet.hxx"
238 #endif
239 */
240 
241 #endif
242