Developer Documentation

VolumeMeshObjectT_impl.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 //=============================================================================
44 //
45 // MyTypes
46 //
47 //=============================================================================
48
49 #define VOLUMEMESHOBJECTT_CC
50
51 //== INCLUDES =================================================================
52
53 #include "VolumeMeshObject.hh"
54
55 #include <OpenFlipper/common/Types.hh>
56 #include <ACG/Scenegraph/DrawModes.hh>
57 #include <OpenFlipper/common/GlobalOptions.hh>
58 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
59
60 #include "VolumeMeshDrawModesContainer.hh"
61
62 #include <ACG/Scenegraph/BoundingBoxNode.hh>
63
64 //== TYPEDEFS =================================================================
65
66 //== CLASS DEFINITION =========================================================
67
68 template<class MeshT>
69 VolumeMeshObject<MeshT>::VolumeMeshObject(const VolumeMeshObject& _object) :
70 BaseObjectData(_object), mesh_(std::make_shared<MeshT>(*_object.mesh_.get())),
71 statusAttrib_(*mesh_),
72 colorAttrib_(*mesh_),
73 normalAttrib_(*mesh_),
74 texcoordAttrib_(*mesh_),
75 meshNode_(NULL),
76 shaderNode_(NULL),
77 textureNode_(NULL)
78 {
79
80 init();
81
82 setName(name());
83 }
84
85 template<class MeshT>
86 VolumeMeshObject<MeshT>::VolumeMeshObject(DataType _typeId) :
87 BaseObjectData(), mesh_(new MeshT()),
88 statusAttrib_(*mesh_),
89 colorAttrib_(*mesh_, ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f) /* Default color */),
90 normalAttrib_(*mesh_),
91 texcoordAttrib_(*mesh_),
92 meshNode_(NULL),
93 shaderNode_(NULL),
94 textureNode_(NULL)
95 {
96
97 setDataType(_typeId);
98 init();
99 }
100
101 template<class MeshT>
102 VolumeMeshObject<MeshT>::~VolumeMeshObject() {
103
104 // Delete the data attached to this object (this will remove all perObject data)
105 // Not the best way to do it but it will work.
106 // This is only necessary if people use references to the mesh below and
107 // they do something with the mesh in the destructor of their
108 // perObjectData.
109 deleteData();
110
111 // No need to delete the scenegraph nodes as this will be managed by baseplugin
112 meshNode_ = 0;
113 shaderNode_ = 0;
114 textureNode_ = 0;
115 }
116
120 template<class MeshT>
121 void VolumeMeshObject<MeshT>::cleanup() {
122
123 BaseObjectData::cleanup();
124
125 meshNode_ = 0;
126 shaderNode_ = 0;
127 textureNode_ = 0;
128
129 init();
130 }
131
135 template<class MeshT>
136 void VolumeMeshObject<MeshT>::init() {
137
138 // Only initialize scenegraph nodes when we initialized a gui!!
139 if(OpenFlipper::Options::nogui())
140 return;
141
142 VolumeMeshDrawModesContainer drawModes; // create this object before initializing the textureNode
143
144 textureNode_ = new ACG::SceneGraph::TextureNode(materialNode() , "NEW TextureNode for ");
145
146 shaderNode_ = new ACG::SceneGraph::ShaderNode(textureNode_ , "NEW ShaderNode for ");
147
148 meshNode_ = new ACG::SceneGraph::VolumeMeshNodeT<MeshT>(*mesh_, statusAttrib_, colorAttrib_, normalAttrib_, texcoordAttrib_, materialNode(), shaderNode_, "NEW VolumeMeshNode");
149
150 if(manipulatorNode() == NULL)
151 std::cerr << "Error when creating volume mesh object! Manipulator node is NULL!" << std::endl;
152
153 if(materialNode() == NULL)
154 std::cerr << "Error when creating mesh object! Material node is NULL!" << std::endl;
155
156 materialNode()->set_point_size(12.0f);
157
158 QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
159
160 std::string shaderDirectory = std::string( shaderDir.toUtf8() );
161 shaderNode_->setShaderDir( shaderDirectory );
162
163 if(!OpenFlipper::Options::coreProfile())
164 {
165 if ( QFile( shaderDir + "Phong/Vertex.glsl").exists() && QFile( shaderDir + "Phong/Fragment.glsl" ).exists() )
166 {
167 shaderNode_->setShader(drawModes.cellsPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
168 shaderNode_->setShader(drawModes.facesPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
169 shaderNode_->setShader(drawModes.halffacesPhongShaded,"Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
170 }
171 else
172 std::cerr << "Shader Files for Phong not found!" << std::endl;
173 }
174
175 // Update all nodes
176 update();
177 }
178
179 // ===============================================================================
180 // Name/Path Handling
181 // ===============================================================================
182
186 template<class MeshT>
187 void VolumeMeshObject<MeshT>::setName(QString _name) {
188 BaseObjectData::setName(_name);
189
190 // No update when gui is not active
191 if(OpenFlipper::Options::nogui())
192 return;
193
194 std::string meshnodename = std::string("VolumeMeshNode for mesh " + _name.toUtf8());
195 meshNode_->name(meshnodename);
196
197 std::string shadernodename = std::string("ShaderNode for mesh " + _name.toUtf8());
198 shaderNode_->name(shadernodename);
199
200 std::string texturenodename = std::string("TextureNode for mesh " + _name.toUtf8());
201 textureNode_->name(texturenodename);
202 }
203
204 // ===============================================================================
205 // Content
206 // ===============================================================================
207
211 template<class MeshT>
212 MeshT* VolumeMeshObject<MeshT>::mesh() {
213 return mesh_.get();
214 }
215
216 template<class MeshT>
217 const MeshT* VolumeMeshObject<MeshT>::mesh() const {
218 return mesh_.get();
219 }
220
225 template<class MeshT>
226 void VolumeMeshObject<MeshT>::update(UpdateType _type) {
227
228 // No update necessary if no gui
229 if(OpenFlipper::Options::nogui())
230 return;
231
232 PluginFunctions::setMainGLContext();
233
234 if(_type.contains(UPDATE_ALL) || _type.contains(UPDATE_TOPOLOGY)) {
235 updateGeometry();
236 updateColor();
237 updateTopology();
238 updateSelection();
239 } else {
240 if(_type.contains(UPDATE_GEOMETRY)) {
241 updateGeometry();
242 }
243 if(_type.contains(UPDATE_SELECTION)) {
244 updateSelection();
245 }
246 if(_type.contains(UPDATE_COLOR)) {
247 updateColor();
248 }
249 if (_type.contains(UPDATE_TEXTURE)){
250 updateTexture();
251 }
252 }
253 }
254
256 template<class MeshT>
257 void VolumeMeshObject<MeshT>::updateSelection() {
258
259 if(meshNode_) {
260 meshNode_->set_selection_changed(true);
261 }
262 }
263
265 template<class MeshT>
266 void VolumeMeshObject<MeshT>::updateGeometry() {
267
268 normalAttrib_.update_face_normals();
269
270 if(meshNode_) {
271 meshNode_->set_geometry_changed(true);
272 }
273 }
274
276 template<class MeshT>
277 void VolumeMeshObject<MeshT>::updateColor() {
278
279 if(meshNode_)
280 meshNode_->set_color_changed(true);
281 }
282
284 template<class MeshT>
285 void VolumeMeshObject<MeshT>::updateTexture()
286 {
287 if(meshNode_)
288 meshNode_->set_texture_changed(true);
289
290 }
291
293 template<class MeshT>
294 void VolumeMeshObject<MeshT>::updateTopology() {
295 if(meshNode_) {
296 meshNode_->set_topology_changed(true);
297 }
298 }
299
300 template<class MeshT>
301 BaseObject* VolumeMeshObject<MeshT>::copy() {
302 VolumeMeshObject< MeshT >* object = new VolumeMeshObject<MeshT>(*this);
303 return static_cast<BaseObject*> (object);
304 }
305
306 template<class MeshT>
307 ACG::SceneGraph::ShaderNode* VolumeMeshObject<MeshT>::shaderNode()
308 {
309 return shaderNode_;
310 }
311
312 template<class MeshT>
313 ACG::SceneGraph::TextureNode* VolumeMeshObject<MeshT>::textureNode()
314 {
315 return textureNode_;
316 }
317
318 // ===============================================================================
319 // Visualization
320 // ===============================================================================
324 template<class MeshT>
325 ACG::SceneGraph::VolumeMeshNodeT<MeshT>* VolumeMeshObject<MeshT>::meshNode() {
326 return meshNode_;
327 }
328
331 template<class MeshT>
332 void VolumeMeshObject<MeshT>::boundingBox(ACG::Vec3d& _bbMin, ACG::Vec3d& _bbMax) {
333 if(meshNode_) {
334 _bbMin = ACG::Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
335 _bbMax = ACG::Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
336 meshNode_->boundingBox(_bbMin, _bbMax);
337 } else {
338 std::cerr << "Error: Bounding box computation via Scenegraph not available without gui." << std::endl;
339 }
340 }
341
342 // ===============================================================================
343 // Object information
344 // ===============================================================================
345
351 template<class MeshT>
352 QString VolumeMeshObject<MeshT>::getObjectinfo() {
353 QString output;
354
355 output += "========================================================================\n";
356 output += BaseObjectData::getObjectinfo();
357
358 if(dataType(typeId("PolyhedralMesh")))
359 output += "Object Contains Polyhedral Mesh : ";
360
361 if(dataType(typeId("HexahedralMesh")))
362 output += "Object Contains Hexahedral Mesh : ";
363
364 output += QString::number(mesh()->n_vertices()) + " vertices\n";
365 output += QString::number(mesh()->n_edges()) += " edges\n";
366 output += QString::number(mesh()->n_halfedges()) += " half-edges\n";
367 output += QString::number(mesh()->n_faces()) += " faces\n";
368 output += QString::number(mesh()->n_halffaces()) += " half-faces\n";
369 output += QString::number(mesh()->n_cells()) += " cells\n";
370
371 output += "========================================================================\n";
372 return output;
373 }
374
375 // ===============================================================================
376 // Picking
377 // ===============================================================================
378
385 template<class MeshT>
386 bool VolumeMeshObject<MeshT>::picked(unsigned int _node_idx) {
387 return (_node_idx == meshNode_->id());
388 }
389
390 template<class MeshT>
391 void VolumeMeshObject<MeshT>::enablePicking(bool _enable) {
392 if(OpenFlipper::Options::nogui())
393 return;
394
395 meshNode_->enablePicking(_enable);
396 shaderNode_->enablePicking(_enable);
397 }
398
399 template<class MeshT>
400 bool VolumeMeshObject<MeshT>::pickingEnabled() {
401 return meshNode_->pickingEnabled();
402 }
403
404 //=============================================================================
405
406 template<class MeshT>
407 BaseNode*
408 VolumeMeshObject<MeshT>::primaryNode() {
409 return boundingBoxNode();
410 }
411
412 //=============================================================================
ShaderNode
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
Definition: SplatCloudTypes.hh:73
VolumeMeshObject::meshNode
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
Definition: VolumeMeshObjectT_impl.hh:325
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
UpdateType
Update type class.
Definition: UpdateType.hh:60
VolumeMeshObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Node.
Definition: VolumeMeshObjectT_impl.hh:391
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
VolumeMeshObject::meshNode_
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode_
Scenegraph Mesh Node.
Definition: VolumeMeshObject.hh:206
VolumeMeshObject::textureNode
ACG::SceneGraph::TextureNode * textureNode()
Return pointer to the texture node.
Definition: VolumeMeshObjectT_impl.hh:313
VolumeMeshObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Node.
Definition: VolumeMeshObjectT_impl.hh:400
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: MeshNode2T_impl.hh:265
VolumeMeshObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
Definition: VolumeMeshObjectT_impl.hh:226
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:233
ACG::SceneGraph::ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T_impl.hh:415
PluginFunctions.hh
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
UPDATE_TEXTURE
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
VolumeMeshObject::normalAttrib_
NormalAttrib normalAttrib_
return a pointer to the mesh
Definition: VolumeMeshObject.hh:147
VolumeMeshObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: VolumeMeshObjectT_impl.hh:352
VolumeMeshObject::texcoordAttrib_
TexCoordAttrib texcoordAttrib_
return a pointer to the mesh
Definition: VolumeMeshObject.hh:149
OpenVolumeMesh::NormalAttrib::update_face_normals
void update_face_normals()
Compute face normals.
Definition: NormalAttribT_impl.hh:84
VolumeMeshObject::statusAttrib_
StatusAttrib statusAttrib_
return a pointer to the mesh
Definition: VolumeMeshObject.hh:143
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:102
VolumeMeshObject
Definition: VolumeMeshObject.hh:63
ACG::SceneGraph::ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: MeshNode2T_impl.hh:423
VolumeMeshObject::updateGeometry
void updateGeometry()
Update Geometry of all data structures.
Definition: VolumeMeshObjectT_impl.hh:266
GlobalOptions.hh
VolumeMeshObject::primaryNode
BaseNode * primaryNode()
Scenegraph Mesh Node.
Definition: VolumeMeshObjectT_impl.hh:408
VolumeMeshObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: VolumeMeshObjectT_impl.hh:187
VolumeMeshObject::shaderNode_
ACG::SceneGraph::ShaderNode * shaderNode_
Scenegraph Shader Node.
Definition: VolumeMeshObject.hh:209
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
ACG::SceneGraph::VolumeMeshNodeT::boundingBox
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
Definition: VolumeMeshNodeT_impl.hh:136
VolumeMeshObject::updateColor
void updateColor()
Update Colors of all data structures.
Definition: VolumeMeshObjectT_impl.hh:277
VolumeMeshObject::colorAttrib_
ColorAttrib colorAttrib_
return a pointer to the mesh
Definition: VolumeMeshObject.hh:145
UPDATE_GEOMETRY
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
VolumeMeshObject::picked
bool picked(unsigned int _node_idx)
detect if the node has been picked
Definition: VolumeMeshObjectT_impl.hh:386
UpdateType::contains
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:104
PluginFunctions::setMainGLContext
void setMainGLContext()
Set current GL Context to main context.
Definition: PluginFunctions.cc:683
VolumeMeshObject::boundingBox
void boundingBox(ACG::Vec3d &_bbMin, typename ACG::Vec3d &_bbMax)
Get the BoundingBox of this object.
Definition: VolumeMeshObjectT_impl.hh:332
std
STL namespace.
VolumeMeshObject::updateTexture
void updateTexture()
Update Texture of all data structures.
Definition: VolumeMeshObjectT_impl.hh:285
VolumeMeshObject::init
virtual void init()
Initialise current object, including all related nodes.
Definition: VolumeMeshObjectT_impl.hh:136
ACG::SceneGraph::ShaderNode
Definition: ShaderNode.hh:81
BaseObjectData::boundingBoxNode
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
Definition: BaseObjectData.cc:271
ACG::SceneGraph::VolumeMeshNodeT< MeshT >
VolumeMeshObject::VolumeMeshObject
VolumeMeshObject(const VolumeMeshObject &_object)
copy constructor
Definition: VolumeMeshObjectT_impl.hh:69
VolumeMeshObject::copy
BaseObject * copy()
Definition: VolumeMeshObjectT_impl.hh:301
VolumeMeshObject::mesh_
ptr::shared_ptr< MeshT > mesh_
return a pointer to the mesh
Definition: VolumeMeshObject.hh:141
ACG::SceneGraph::MaterialNode::set_point_size
void set_point_size(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:486
Types.hh
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
BaseObject
Definition: BaseObject.hh:82
VolumeMeshObject::updateSelection
void updateSelection()
Call this function to update the selection.
Definition: VolumeMeshObjectT_impl.hh:257
OpenMesh::VectorT< float, 4 >
VolumeMeshObject::~VolumeMeshObject
virtual ~VolumeMeshObject()
destructor
Definition: VolumeMeshObjectT_impl.hh:102
ACG::SceneGraph::ACG::SceneGraph::BaseNode::pickingEnabled
bool pickingEnabled()
Definition: MeshNode2T_impl.hh:269
UPDATE_TOPOLOGY
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
VolumeMeshDrawModesContainer
This class provides easy access to DrawModes supported by OpenVolumeMesh.
Definition: VolumeMeshDrawModesContainer.hh:50
VolumeMeshObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: VolumeMeshObjectT_impl.hh:121
VolumeMeshObject::shaderNode
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
Definition: VolumeMeshObjectT_impl.hh:307
BaseObjectData
Definition: BaseObjectData.hh:102
VolumeMeshObject::updateTopology
void updateTopology()
Update Topology of all data structures.
Definition: VolumeMeshObjectT_impl.hh:294
UPDATE_COLOR
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
VolumeMeshObject::mesh
MeshT * mesh()
return a pointer to the mesh
Definition: VolumeMeshObjectT_impl.hh:212
typeId
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
Definition: Types.cc:139
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:229
VolumeMeshObject::textureNode_
ACG::SceneGraph::TextureNode * textureNode_
Scenegraph Texture Node.
Definition: VolumeMeshObject.hh:212
BaseObjectData::manipulatorNode
QtTranslationManipulatorNode * manipulatorNode()
Definition: BaseObjectData.cc:255
ACG::SceneGraph::TextureNode
Definition: TextureNode.hh:87