opensurgsim
OctreeNodePlyReaderDelegate.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DATASTRUCTURES_OCTREENODEPLYREADERDELEGATE_H
17 #define SURGSIM_DATASTRUCTURES_OCTREENODEPLYREADERDELEGATE_H
18 
19 #include "SurgSim/DataStructures/PlyReaderDelegate.h"
20 #include "SurgSim/DataStructures/OctreeNode.h"
21 #include "SurgSim/DataStructures/EmptyData.h"
22 
23 namespace SurgSim
24 {
25 namespace DataStructures
26 {
27 
31 {
32 public:
33 
36 
39 
40  bool registerDelegate(PlyReader* reader) override;
41 
42  bool fileIsAcceptable(const PlyReader& reader) override;
43 
49  void* beginBounds(const std::string& elementName, size_t count);
50 
56  void* beginDimension(const std::string& elementName, size_t count);
57 
63  void* beginSpacing(const std::string& elementName, size_t count);
64 
69  virtual void* beginVoxel(const std::string& elementName, size_t count);
70 
74  virtual void processVoxel(const std::string& elementName) = 0;
75 
76 protected:
78  virtual void initializeOctree() = 0;
79 
81  struct BoundsData
82  {
83  double xMin = std::numeric_limits<double>::signaling_NaN();
84  double yMin = std::numeric_limits<double>::signaling_NaN();
85  double zMin = std::numeric_limits<double>::signaling_NaN();
86  double xMax = std::numeric_limits<double>::signaling_NaN();
87  double yMax = std::numeric_limits<double>::signaling_NaN();
88  double zMax = std::numeric_limits<double>::signaling_NaN();
89  } m_bounds;
90 
92  Eigen::AlignedBox<double, 3> m_boundingBox;
93 
95  struct SpacingData
96  {
97  double x = std::numeric_limits<double>::signaling_NaN();
98  double y = std::numeric_limits<double>::signaling_NaN();
99  double z = std::numeric_limits<double>::signaling_NaN();
100  } m_spacing;
101 
104  {
105  unsigned int x = 0;
106  unsigned int y = 0;
107  unsigned int z = 0;
108  } m_dimension;
109 
111  struct VoxelData
112  {
113  double x = std::numeric_limits<double>::signaling_NaN();
114  double y = std::numeric_limits<double>::signaling_NaN();
115  double z = std::numeric_limits<double>::signaling_NaN();
116  } m_voxel;
117 
119  int m_numLevels = -1;
120 
124  bool m_haveDimensions;
125  bool m_haveBounds;
127 
128 };
129 
133 template <typename Data>
135 {
136 public:
137 
140 
143  explicit OctreeNodePlyReaderDelegate(std::shared_ptr<OctreeNode<Data>> octree);
144 
146  virtual ~OctreeNodePlyReaderDelegate();
147 
149  std::shared_ptr<OctreeNode<Data>> getOctree();
150 
151  void processVoxel(const std::string& elementName) override;
152 
153  void initializeOctree() override;
154 
155 private:
156 
158  std::shared_ptr<OctreeNode<Data>> m_octree;
159 };
160 
161 }
162 }
163 
164 #include "SurgSim/DataStructures/OctreeNodePlyReaderDelegate-inl.h"
165 
166 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void * beginBounds(const std::string &elementName, size_t count)
Callback function, begin the processing of the bounds.
Definition: OctreeNodePlyReaderDelegate.cpp:101
bool fileIsAcceptable(const PlyReader &reader) override
Check whether the file in the reader can be used with this delegate, this gives the delegate a chance...
Definition: OctreeNodePlyReaderDelegate.cpp:83
bool registerDelegate(PlyReader *reader) override
Registers the delegate with the reader.
Definition: OctreeNodePlyReaderDelegate.cpp:38
Eigen::AlignedBox< double, 3 > m_boundingBox
Bounding box, will be initialized from the file.
Definition: OctreeNodePlyReaderDelegate.h:92
virtual void * beginVoxel(const std::string &elementName, size_t count)
Callback function, begin the processing of the voxels.
Definition: OctreeNodePlyReaderDelegate.cpp:122
Data Structure to receive the bounds information.
Definition: OctreeNodePlyReaderDelegate.h:81
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
virtual ~OctreeNodePlyReaderDelegateBase()
Destructor.
Definition: OctreeNodePlyReaderDelegate.cpp:33
void * beginSpacing(const std::string &elementName, size_t count)
Callback function, begin the processing of the bounds.
Definition: OctreeNodePlyReaderDelegate.cpp:115
virtual void initializeOctree()=0
Set up the octree, this is left up to the derived classes.
Subclass the OctreeNodePLyReaderDelegateBase class to enable processing of the templated data...
Definition: OctreeNode.h:113
Delegate to read Octrees from ply files, this is the abstract base class, to let us modify loading by...
Definition: OctreeNodePlyReaderDelegate.h:30
void * beginDimension(const std::string &elementName, size_t count)
Callback function, begin the processing of the dimension.
Definition: OctreeNodePlyReaderDelegate.cpp:108
bool m_haveSpacing
Definition: OctreeNodePlyReaderDelegate.h:123
virtual void processVoxel(const std::string &elementName)=0
Callback function to process one voxel.
Data structure to receive the dimension information from the file.
Definition: OctreeNodePlyReaderDelegate.h:103
OctreeNodePlyReaderDelegateBase()
Constructor.
Definition: OctreeNodePlyReaderDelegate.cpp:25
int m_numLevels
Calculated number of levels for the octree.
Definition: OctreeNodePlyReaderDelegate.h:119
Data structure to receive the specific voxel information from the file.
Definition: OctreeNodePlyReaderDelegate.h:111
Octree data structure.
Definition: OctreeNode.h:131
PlyReaderDelegate abstract class.
Definition: PlyReaderDelegate.h:31
Data structure to receive the spacing information from the file.
Definition: OctreeNodePlyReaderDelegate.h:95