65 #include <ACG/Scenegraph/DrawModes.hh>
74 template <
class MeshT >
103 template <
class MeshT >
124 template <
class MeshT >
135 if ( mesh_ != NULL) {
139 std::cerr <<
"Destructor error : Mesh already deleted" << std::endl;
142 if ( triangle_bsp_ != 0 )
143 delete triangle_bsp_;
159 template <
class MeshT >
162 if ( mesh_ != NULL) {
166 std::cerr <<
"Cleanup error : Triangle Mesh already deleted" << std::endl;
169 if ( triangle_bsp_ != 0 )
170 delete triangle_bsp_;
191 template <
class MeshT >
197 mesh_ =
new MeshT(*_mesh);
200 mesh_->request_vertex_normals();
201 mesh_->request_face_normals();
202 mesh_->request_vertex_status();
203 mesh_->request_halfedge_status();
204 mesh_->request_face_status();
205 mesh_->request_edge_status();
206 mesh_->request_vertex_colors();
207 mesh_->request_face_colors();
210 if ( OpenFlipper::Options::nogui() )
214 if ( manipulatorNode() == NULL)
215 std::cerr <<
"Error when creating Mesh Object! manipulatorNode is NULL!" << std::endl;
224 QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
226 std::string shaderDirectory = std::string( shaderDir.toUtf8() );
227 shaderNode_->setShaderDir( shaderDirectory );
230 if ( QFile( shaderDir +
"Phong/Vertex.glsl").exists() && QFile( shaderDir +
"Phong/Fragment.glsl" ).exists() )
233 std::cerr <<
"Shader Files for Phong not found!" << std::endl;
238 statusNode_->set_point_size(4.0);
239 statusNode_->set_color(
ACG::Vec4f(1.0f,0.0f,0.0f,1.0f));
240 statusNode_->set_base_color(
ACG::Vec4f(1.0f,0.0f,0.0f,1.0f));
247 areaNode_->set_round_points(
true);
248 areaNode_->enable_alpha_test(0.5);
249 areaNode_->set_point_size(7.0);
250 areaNode_->set_color(
ACG::Vec4f(0.4f, 0.4f, 1.0f, 1.0f));
257 handleNode_->set_round_points(
true);
258 handleNode_->enable_alpha_test(0.5);
259 handleNode_->set_line_width(2.0);
260 handleNode_->set_point_size(7.0);
261 handleNode_->set_color(
ACG::Vec4f(0.2f, 1.0f, 0.2f, 1.0f));
268 featureNode_->set_round_points(
true);
269 featureNode_->enable_alpha_test(0.5);
270 featureNode_->set_line_width(2.0);
271 featureNode_->set_point_size(7.0);
272 featureNode_->set_color(
ACG::Vec4f(1.0f, 0.2f, 1.0f, 1.0f));
273 featureNode_->set_base_color(
ACG::Vec4f(1.0f, 0.2f, 1.0f, 1.0f));
280 statusNode_->
setDrawMesh(meshNode_->getDrawMesh());
281 featureNode_->setDrawMesh(meshNode_->getDrawMesh());
282 areaNode_->setDrawMesh(meshNode_->getDrawMesh());
283 handleNode_->setDrawMesh(meshNode_->getDrawMesh());
297 featureNode_->set_parent(statusView_);
310 template <
class MeshT >
315 if ( OpenFlipper::Options::nogui() )
318 std::string nodename = std::string(
"StatusNode for mesh " + _name.toUtf8() );
319 statusNode_->name( nodename );
321 nodename = std::string(
"AreaNode for mesh " + _name.toUtf8() );
322 areaNode_->name( nodename );
324 nodename = std::string(
"HandleNode for mesh " + _name.toUtf8() );
325 handleNode_->name( nodename );
327 nodename = std::string(
"FeatureNode for mesh " + _name.toUtf8() );
328 featureNode_->name( nodename );
330 nodename = std::string(
"TextureNode for mesh "+ _name.toUtf8() );
331 textureNode_->name( nodename );
333 nodename = std::string(
"ShaderNode for mesh "+ _name.toUtf8() );
334 shaderNode_->name( nodename );
336 nodename = std::string(
"MeshNode for mesh " + _name.toUtf8() );
337 meshNode_->name( nodename );
339 nodename = std::string(
"StatusViewNode for mesh " + _name.toUtf8() );
340 statusView_->name( nodename );
350 template <
class MeshT >
359 template <
class MeshT >
363 if ( OpenFlipper::Options::nogui() )
374 updateModelingRegions();
385 updateModelingRegions();
397 template <
class MeshT >
401 statusNode_->updateSelection();
406 template <
class MeshT >
410 meshNode_->update_geometry();
415 statusNode_->updateGeometry();
416 featureNode_->updateGeometry();
417 areaNode_->updateGeometry();
418 handleNode_->updateGeometry();
422 invalidateTriangleBsp();
426 template <
class MeshT >
429 meshNode_->update_color();
433 template <
class MeshT >
436 meshNode_->update_topology();
437 statusNode_->updateTopology();
438 featureNode_->updateTopology();
439 areaNode_->updateTopology();
440 handleNode_->updateTopology();
442 invalidateTriangleBsp();
446 template <
class MeshT >
448 if ( areaNode_ && handleNode_ ) {
449 areaNode_->updateSelection();
450 handleNode_->updateSelection();
455 template <
class MeshT >
458 featureNode_->updateSelection();
462 template <
class MeshT >
464 meshNode_->update_textures();
471 template <
class MeshT >
476 statusNode_->set_color(_color);
477 statusNode_->set_base_color(_color);
481 template <
class MeshT >
485 return statusNode_->base_color();
490 template <
class MeshT >
495 areaNode_->set_color(_color);
496 areaNode_->set_base_color(_color);
499 template <
class MeshT >
503 return areaNode_->base_color();
508 template <
class MeshT >
513 featureNode_->set_color(_color);
514 featureNode_->set_base_color(_color);
517 template <
class MeshT >
521 return featureNode_->base_color();
526 template <
class MeshT >
531 handleNode_->set_color(_color);
532 handleNode_->set_base_color(_color);
535 template <
class MeshT >
539 return handleNode_->base_color();
548 template <
class MeshT >
556 template <
class MeshT >
563 template <
class MeshT >
574 template <
class MeshT >
583 template <
class MeshT >
590 template <
class MeshT >
600 areaNode_->set_status( status );
603 if ( _bit & HANDLEAREA )
604 handleNode_->set_status( status );
608 template <
class MeshT >
613 template <
class MeshT >
620 if ( _bit & HANDLEAREA )
629 template <
class MeshT >
636 template <
class MeshT >
639 _bbMin =
ACG::Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
640 _bbMax =
ACG::Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
641 meshNode_->boundingBox(_bbMin,_bbMax);
643 std::cerr <<
"Error: Bounding box computation via Scenegraph not available without gui" << std::endl;
656 template <
class MeshT >
659 setFromFileName(_filename);
664 std::string filename = std::string( _filename.toUtf8() );
670 if ( dataType() ==
typeid(
"TriangleMesh") )
671 std::cerr <<
"Main Application : Read error for Triangle Mesh at "<< filename << std::endl;
672 if ( dataType() ==
typeid(
"PolyMesh") )
673 std::cerr <<
"Main Application : Read error for Poly Mesh\n";
695 template <
class MeshT >
699 output +=
"========================================================================\n";
702 if ( dataType(
typeId(
"TriangleMesh") ) )
703 output +=
"Object Contains Triangle Mesh : ";
705 if ( dataType(
typeId(
"PolyMesh") ) )
706 output +=
"Object Contains Poly Mesh : ";
708 output += QString::number( mesh()->n_vertices() ) +
" vertices, ";
709 output += QString::number( mesh()->n_edges() ) +=
" edges ";
710 output += QString::number( mesh()->n_faces() ) +=
" faces.\n";
712 output +=
"========================================================================\n";
726 template <
class MeshT >
728 return ( _node_idx == meshNode_->id() );
732 template <
class MeshT >
734 if ( OpenFlipper::Options::nogui())
737 meshNode_->enablePicking( _enable );
738 areaNode_->enablePicking( _enable );
739 handleNode_->enablePicking( _enable );
740 featureNode_->enablePicking( _enable );
741 textureNode_->enablePicking( _enable );
742 shaderNode_->enablePicking( _enable );
745 template <
class MeshT >
747 return meshNode_->pickingEnabled();
754 template <
class MeshT >
758 if ( ! dataType(
typeId(
"TriangleMesh") ) ) {
759 std::cerr <<
"Bsps are only supported for triangle meshes." << std::endl;
764 if ( triangle_bsp_ == 0 )
770 triangle_bsp_->reserve(mesh()->n_faces());
772 typename MeshT::FIter f_it = mesh()->faces_begin();
773 typename MeshT::FIter f_end = mesh()->faces_end();
775 for (; f_it!=f_end; ++f_it)
776 triangle_bsp_->push_back(*f_it);
778 triangle_bsp_->build(10, 100);
782 return triangle_bsp_;
785 template <
class MeshT >
788 if ( triangle_bsp_ != 0 )
790 delete triangle_bsp_;
794 return requestTriangleBsp();
797 template <
class MeshT >
800 if ( triangle_bsp_ != 0 )
802 delete triangle_bsp_;
808 template <
class MeshT >
811 return triangle_bsp_ != 0;
817 template <
class MeshT >
820 return boundingBoxNode();
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
QString getObjectinfo()
Get all Info for the Object as a string.
void setDrawMesh(DrawMeshT< Mesh > *_drawmesh)
Set drawmesh.
ACG::SceneGraph::MeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
void setFeatureColor(const ACG::Vec4f &_color)
set color for features
void hideArea(StatusBits _bit, bool _hide)
Hide or show the area Nodes of the object.
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
MeshT * mesh()
return a pointer to the mesh
bool hasBsp() const
check if a BSP has been computed and is valid
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
BaseNode * primaryNode()
Status Node for a mesh, visualizing the selection state of a mesh.
virtual void cleanup()
Reset current object, including all related nodes.
void updateColor()
Update Colors of all data structures.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
virtual ~MeshObject()
destructor
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
bool areaVisible(StatusBits _bit)
Return if the selected areas are currently visible.
void setName(QString _name)
Set the name of the Object.
bool loadMesh(QString _filename)
Load a mesh from the given file.
VectorT< float, 4 > Vec4f
OMTriangleBSP * requestTriangleBsp()
VectorT< double, 3 > Vec3d
ACG::Vec4f handleColor() const
get color for handles. returns -1 vector, if handle node does not exists
ACG::Vec4f areaColor() const
get color for areas. returns -1 vector, if handle node does not exists
bool featuresVisible()
return if the feature Node of the object is currently visible
virtual void init(MeshT *_mesh=0)
Initialise current object, including all related nodes.
MeshObject(const MeshObject &_object)
copy constructor
OMTriangleBSP * resetTriangleBsp()
ACG::Vec4f featureColor() const
get color for features. returns -1 vector, if handle node does not exists
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
void hideFeatures(bool _hide)
Hide or show the feature Node of the object.
bool selectionVisible()
return if the selections are currently visible
void boundingBox(ACG::Vec3d &_bbMin, typename ACG::Vec3d &_bbMax)
Get the BoundingBox of this object.
void updateFeatures()
Update Feature Visualization Node.
void setHandleColor(const ACG::Vec4f &_color)
set color for handles
void setAreaColor(const ACG::Vec4f &_color)
set color for areas
void set_parent(BaseNode *_parent)
Set the parent of this node.
void updateModelingRegions()
Call this function to update the modeling regions.
void invalidateTriangleBsp()
void updateGeometry()
Update Geometry of all data structures.
void enablePicking(bool _enable)
Enable or disable picking for this Node.
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
ACG::Vec4f selectionColor() const
get color for selection. returns -1 vector, if handle node does not exists
void setDataType(DataType _type)
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
void updateSelection()
Call this function to update the modeling regions.
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode of the current mesh.
void hideSelection(bool _hide)
Hide or show the selection Node of the object.
void update_normals()
Compute normals for all primitives.
void updateTexture()
Update Texture of all data structures.
Hide this node, but draw children.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
bool picked(uint _node_idx)
detect if the node has been picked
bool pickingEnabled()
Check if picking is enabled for this Node.
MeshT * mesh_
pointer to the mesh
void setMainGLContext()
Set current GL Context to main context.
void setSelectionColor(const ACG::Vec4f &_color)
set color for selection
DrawMode NONE
not a valid draw mode
void updateTopology()
Update Topology of all data structures.