Commit 7bcce11b authored by Jan Möbius's avatar Jan Möbius
Browse files

Cleanup the Objecttypes and nodes

parent 0c1aa62b
Pipeline #3346 passed with stage
in 40 minutes and 2 seconds
...@@ -54,17 +54,16 @@ ...@@ -54,17 +54,16 @@
//============================================================================= //=============================================================================
/** /**
* \file PolyLine.hh * \file PolyLineCollection.hh
* This File contains all required includes for using Poly Line Collections * This File contains all required includes for using PolyLine Collections
*/ */
#ifndef POLYLINE_COLLECTION_INCLUDE_HH #pragma once
#define POLYLINE_COLLECTION_INCLUDE_HH
//== INCLUDES ================================================================= //== INCLUDES =================================================================
/** \def DATA_POLY_LINE /** \def DATA_POLY_LINE_COLLECTION
* Use this macro to reference polygonal lines * Use this macro to reference polygonal lines
*/ */
#define DATA_POLY_LINE_COLLECTION typeId("PolyLineCollection") #define DATA_POLY_LINE_COLLECTION typeId("PolyLineCollection")
...@@ -75,4 +74,3 @@ ...@@ -75,4 +74,3 @@
#include "PolyLineCollectionObject.hh" #include "PolyLineCollectionObject.hh"
#endif // POLYLINE_COLLECTION_INCLUDE_HH
\ No newline at end of file
...@@ -88,7 +88,8 @@ PolyLineCollectionNodeT<PolyLineCollection>::PolyLineCollectionNodeT(PolyLineCol ...@@ -88,7 +88,8 @@ PolyLineCollectionNodeT<PolyLineCollection>::PolyLineCollectionNodeT(PolyLineCol
polyline_collection_(_pl), polyline_collection_(_pl),
vbo_(0), vbo_(0),
updateVBO_(true), updateVBO_(true),
sphere_(0) sphere_(0),
total_vertex_count_(0)
{ {
// Initial default draw mode // Initial default draw mode
...@@ -172,7 +173,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode) ...@@ -172,7 +173,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
float point_size_old = _state.point_size(); float point_size_old = _state.point_size();
_state.set_point_size(point_size_old+4.0f); _state.set_point_size(point_size_old+4.0f);
_state.set_color( Vec4f(1,0,0,1) ); _state.set_color( Vec4f(1.0f,0.0f,0.0f,1.0f) );
// Draw selected polylines // Draw selected polylines
for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){ for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){
...@@ -234,7 +235,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode) ...@@ -234,7 +235,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
if(polyline){ if(polyline){
int offset = offsets_[it.idx()].first; int offset = offsets_[it.idx()].first;
for(int i = 0; i < int(polyline->n_vertices()); ++i){ for(size_t i = 0; i < polyline->n_vertices(); ++i){
if(!polyline->is_closed() && i == polyline->n_vertices() - 1){ if(!polyline->is_closed() && i == polyline->n_vertices() - 1){
continue; continue;
} }
...@@ -267,7 +268,7 @@ void ...@@ -267,7 +268,7 @@ void
PolyLineCollectionNodeT<PolyLineCollection>:: PolyLineCollectionNodeT<PolyLineCollection>::
pick(GLState& _state, PickTarget _target) pick(GLState& _state, PickTarget _target)
{ {
// TODO
if ( polyline_collection_.n_polylines() == 0 ) if ( polyline_collection_.n_polylines() == 0 )
return; return;
...@@ -331,39 +332,9 @@ void ...@@ -331,39 +332,9 @@ void
PolyLineCollectionNodeT<PolyLineCollection>:: PolyLineCollectionNodeT<PolyLineCollection>::
updateVBO() { updateVBO() {
// register custom properties defined in polyline
/*for (unsigned int i = 0; i < polyline_.get_num_custom_properties(); ++i) {
typename PolyLine::CustomPropertyHandle proph = polyline_.enumerate_custom_property_handles(i);
const void* propDataBuf = polyline_.get_custom_property_buffer(proph);
typename std::map< typename PolyLine::CustomPropertyHandle, int >::iterator mapEntry = polylinePropMap_.find(proph);
// insert newly defined properties
if (mapEntry == polylinePropMap_.end()) {
// setup element description
ACG::VertexElement desc;
unsigned int propSize = 0;
polyline_.get_custom_property_shader_binding(proph, &propSize, &desc.shaderInputName_, &desc.type_);
// assume aligned memory without byte padding
desc.numElements_ = propSize / VertexDeclaration::getGLTypeSize(desc.type_);
desc.pointer_ = 0;
polylinePropMap_[proph] = addCustomBuffer(desc, propDataBuf);
}
else // otherwise update pointer of property data buffer
setCustomBuffer(mapEntry->second, propDataBuf);
}*/
bool lines_did_change = false; bool lines_did_change = false;
if(int(offsets_.size()) != polyline_collection_.n_polylines() ){ if( offsets_.size() != polyline_collection_.n_polylines() ){
offsets_.resize(polyline_collection_.n_polylines()); offsets_.resize(polyline_collection_.n_polylines());
lines_did_change = true; lines_did_change = true;
} }
...@@ -371,10 +342,10 @@ updateVBO() { ...@@ -371,10 +342,10 @@ updateVBO() {
int offset = 0; int offset = 0;
total_vertex_count_ = 0; total_vertex_count_ = 0;
for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){ for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
std::pair<int, int> current_offset; std::pair<size_t, size_t> current_offset;
current_offset.first = offset; current_offset.first = offset;
if(*it){ if(*it){
current_offset.second = int(it->n_vertices()) + 1; current_offset.second = it->n_vertices() + 1;
}else{ }else{
current_offset.second = 0; current_offset.second = 0;
} }
...@@ -398,49 +369,16 @@ updateVBO() { ...@@ -398,49 +369,16 @@ updateVBO() {
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION); vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION);
vertexDecl_.addElement(GL_UNSIGNED_BYTE, 4, ACG::VERTEX_USAGE_COLOR); vertexDecl_.addElement(GL_UNSIGNED_BYTE, 4, ACG::VERTEX_USAGE_COLOR);
// vertexDecl_.setVertexStride(3*sizeof(float) + 4);
// Use the normals if available
//if ( polyline_.vertex_normals_available() )
// vertexDecl_.addElement(GL_FLOAT, 3 , ACG::VERTEX_USAGE_NORMAL);
// Add custom vertex elements to declaration
/*for (size_t i = 0; i < customBuffers_.size(); ++i) {
ACG::VertexElement tmp = customBuffers_[i].first;
tmp.pointer_ = 0;
tmp.usage_ = ACG::VERTEX_USAGE_SHADER_INPUT;
vertexDecl_.addElement(&tmp);
}*/
// create vbo if it does not exist // create vbo if it does not exist
if (!vbo_) if (!vbo_)
GLState::genBuffersARB(1, &vbo_); GLState::genBuffersARB(1, &vbo_);
/* int vertex_count = 0;
for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
typename PolyLineCollection::PolyLine* polyline = *it;
if(polyline->n_vertices() > 0){
vertex_count += polyline->n_vertices()+1;
}
}*/
// std::cout << "Stride: " << vertexDecl_.getVertexStride() << std::endl;
// size in bytes of vbo, create additional vertex for closed loop indexing // size in bytes of vbo, create additional vertex for closed loop indexing
unsigned int bufferSize = vertexDecl_.getVertexStride() * offset; unsigned int bufferSize = vertexDecl_.getVertexStride() * offset;
// Create the required array // Create the required array
char* vboData_ = new char[bufferSize]; char* vboData_ = new char[bufferSize];
/*// Index buffer for selected vertices
selectedVertexIndexBuffer_.clear();
// Index buffer for selected vertices
selectedEdgeIndexBuffer_.clear();*/
// int offset = 0;
for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){ for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
typename PolyLineCollection::PolyLine* polyline = *it; typename PolyLineCollection::PolyLine* polyline = *it;
...@@ -527,7 +465,7 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S ...@@ -527,7 +465,7 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Viewport size // Viewport size
ACG::Vec2f screenSize(float(_state.viewport_width()), float(_state.viewport_height())); ACG::Vec2f screenSize(float(_state.viewport_width()), float(_state.viewport_height()));
for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i) { for (size_t i = 0; i < _drawMode.getNumLayers(); ++i) {
ACG::SceneGraph::Material localMaterial = *_mat; ACG::SceneGraph::Material localMaterial = *_mat;
const ACG::SceneGraph::DrawModes::DrawModeProperties* props = _drawMode.getLayer(i); const ACG::SceneGraph::DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
...@@ -552,15 +490,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S ...@@ -552,15 +490,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Point Size geometry shader // Point Size geometry shader
ro.setupPointRendering(_mat->pointSize(), screenSize); ro.setupPointRendering(_mat->pointSize(), screenSize);
/* if (!selectedVertexIndexBuffer_.empty())
{
ro.glDrawElements(GL_POINTS, selectedVertexIndexBuffer_.size(), GL_UNSIGNED_INT, &(selectedVertexIndexBuffer_[0]));
// apply user settings
applyRenderObjectSettings(props->primitive(), &ro);
_renderer->addRenderObject(&ro);
}*/
// Render all vertices (ignore selection here!) // Render all vertices (ignore selection here!)
ro.debugName = "polylinecollection.Points"; ro.debugName = "polylinecollection.Points";
localMaterial.baseColor(defaultColor); localMaterial.baseColor(defaultColor);
...@@ -589,16 +518,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S ...@@ -589,16 +518,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Line Width geometry shader // Line Width geometry shader
ro.setupLineRendering(_state.line_width(), screenSize); ro.setupLineRendering(_state.line_width(), screenSize);
/* if (!selectedEdgeIndexBuffer_.empty())
{
ro.glDrawElements(GL_LINES, selectedEdgeIndexBuffer_.size(), GL_UNSIGNED_INT, &(selectedEdgeIndexBuffer_[0]));
// apply user settings
applyRenderObjectSettings(props->primitive(), &ro);
_renderer->addRenderObject(&ro);
}*/
ro.debugName = "polylinecollection.Wireframe"; ro.debugName = "polylinecollection.Wireframe";
localMaterial.baseColor(defaultColor); localMaterial.baseColor(defaultColor);
ro.setMaterial(&localMaterial); ro.setMaterial(&localMaterial);
...@@ -630,37 +549,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S ...@@ -630,37 +549,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
} }
//----------------------------------------------------------------------------
/*template <class PolyLine>
int
PolyLineNodeT<PolyLine>::
addCustomBuffer( const ACG::VertexElement& _desc, const void* _buffer) {
if (_buffer) {
customBuffers_.push_back( std::pair<ACG::VertexElement, const void*>(_desc, _buffer) );
update();
return int(customBuffers_.size()-1);
}
else
{
std::cerr << "PolyLineNodeT::addCustomBuffer - null pointer buffer" << std::endl;
return -1;
}
}*/
//----------------------------------------------------------------------------
/*template <class PolyLine>
void
PolyLineNodeT<PolyLine>::
setCustomBuffer( int _id, const void* _buffer) {
customBuffers_[_id].second = _buffer;
update();
}*/
//============================================================================= //=============================================================================
} // namespace SceneGraph } // namespace SceneGraph
} // namespace ACG } // namespace ACG
......
...@@ -71,11 +71,9 @@ namespace SceneGraph { ...@@ -71,11 +71,9 @@ namespace SceneGraph {
/** \class PolyLineNodeT PolyLineNodeT.hh <ACG/.../PolyLineNodeT.hh> /** \class PolyLineNodeT PolyLineCollectionNodeT.hh <ACG/.../PolyLineCollectionNodeT.hh>
Brief Description. This Node provides support for rendering polyline collections.
A more elaborate description follows.
*/ */
template <class PolyLineCollection> template <class PolyLineCollection>
...@@ -121,11 +119,6 @@ public: ...@@ -121,11 +119,6 @@ public:
/// Trigger an update of the vbo /// Trigger an update of the vbo
void update() { updateVBO_ = true; }; void update() { updateVBO_ = true; };
void reset_vbo(){
offsets_.clear();
updateVBO_ = true;
}
private: private:
/// Copy constructor (not used) /// Copy constructor (not used)
...@@ -139,7 +132,7 @@ private: ...@@ -139,7 +132,7 @@ private:
/** \brief Trigger an update of the vbo /** \brief Trigger an update of the vbo
* *
* If the polyLine is changed, you have to call this function to update the buffers. * If the polyLineCollection is changed, you have to call this function to update the buffers.
* *
*/ */
void updateVBO(); void updateVBO();
...@@ -153,7 +146,7 @@ private: ...@@ -153,7 +146,7 @@ private:
private: private:
/// The associated poly line /// The associated poly line collection
PolyLineCollection& polyline_collection_; PolyLineCollection& polyline_collection_;
/// VBO used to render the poly line /// VBO used to render the poly line
...@@ -165,9 +158,9 @@ private: ...@@ -165,9 +158,9 @@ private:
/// Sphere for VertexSphere DrawMode /// Sphere for VertexSphere DrawMode
GLSphere* sphere_; GLSphere* sphere_;
std::vector<std::pair<int, int> > offsets_; std::vector<std::pair<size_t, size_t> > offsets_;
int total_vertex_count_; size_t total_vertex_count_;
}; };
......
...@@ -67,11 +67,11 @@ ...@@ -67,11 +67,11 @@
//== CLASS DEFINITION ========================================================= //== CLASS DEFINITION =========================================================
/** Constructor for PolyLine Objects. This object class gets a Separator Node giving /** Constructor for PolyLine Collection Objects. This object class gets a Separator Node giving
* the root node to which it should be connected. The line is generated internally * the root node to which it should be connected. The collection is generated internally
* and all nodes for visualization will be added below the scenegraph node.\n * and all nodes for visualization will be added below the scenegraph node.\n
* You dont need to create an object of this type manually. Use * You don't need to create an object of this type manually. Use
* PluginFunctions::addPolyLine instead. ( see Types.hh::DataType ) * PluginFunctions::addPolyLineCollection instead. ( see Types.hh::DataType )
*/ */
PolyLineCollectionObject::PolyLineCollectionObject() : PolyLineCollectionObject::PolyLineCollectionObject() :
BaseObjectData( ), BaseObjectData( ),
...@@ -96,8 +96,8 @@ PolyLineCollectionObject::PolyLineCollectionObject(const PolyLineCollectionObjec ...@@ -96,8 +96,8 @@ PolyLineCollectionObject::PolyLineCollectionObject(const PolyLineCollectionObjec
setName( name() ); setName( name() );
} }
/** Destructor for PolyLine Objects. The destructor deletes the Line and all /** Destructor for PolyLineCollection Objects. The destructor deletes the Collection and all
* Scenegraph nodes associated with the Line or the object. * Scenegraph nodes associated with the Collection or the object.
*/ */
PolyLineCollectionObject::~PolyLineCollectionObject() PolyLineCollectionObject::~PolyLineCollectionObject()
{ {
...@@ -108,7 +108,7 @@ PolyLineCollectionObject::~PolyLineCollectionObject() ...@@ -108,7 +108,7 @@ PolyLineCollectionObject::~PolyLineCollectionObject()
// perObjectData. // perObjectData.
deleteData(); deleteData();
// Delete the Mesh only, if this object contains a mesh // Delete the collection only, if this object contains a collection
if ( collection_ != NULL) { if ( collection_ != NULL) {
delete collection_; delete collection_;
collection_ = NULL; collection_ = NULL;
...@@ -116,15 +116,16 @@ PolyLineCollectionObject::~PolyLineCollectionObject() ...@@ -116,15 +116,16 @@ PolyLineCollectionObject::~PolyLineCollectionObject()
std::cerr << "Destructor error : Line Collection already deleted" << std::endl; std::cerr << "Destructor error : Line Collection already deleted" << std::endl;
} }
// No need to delete the scenegraph Nodes as this will be managed by baseplugin // No need to delete the scenegraph Nodes as this will be managed by BasePlugin
collectionNode_ = NULL; collectionNode_ = NULL;
} }
/** Cleanup Function for Line Objects. Deletes the contents of the whole object and /** Cleanup Function for Collection Objects. Deletes the contents of the whole object and
* calls PolyLineObject::init afterwards. * calls PolyLineCollection::init afterwards.
*/ */
void PolyLineCollectionObject::cleanup() { void PolyLineCollectionObject::cleanup() {
// Delete the Line only, if this object contains a line
// Delete the Collection only, if this object contains a Collection
if ( collection_ != NULL) { if ( collection_ != NULL) {
delete collection_; delete collection_;
collection_ = NULL; collection_ = NULL;
...@@ -150,8 +151,8 @@ BaseObject* PolyLineCollectionObject::copy() { ...@@ -150,8 +151,8 @@ BaseObject* PolyLineCollectionObject::copy() {
return dynamic_cast< BaseObject* >(object); return dynamic_cast< BaseObject* >(object);
} }
/** This function initalizes the line object. It creates the scenegraph nodes, /** This function initializes the Collection object. It creates the scenegraph nodes,
* the line. * the Collection.
*/ */
void PolyLineCollectionObject::init(PolyLineCollection* _collection) { void PolyLineCollectionObject::init(PolyLineCollection* _collection) {
...@@ -165,7 +166,7 @@ void PolyLineCollectionObject::init(PolyLineCollection* _collection) { ...@@ -165,7 +166,7 @@ void PolyLineCollectionObject::init(PolyLineCollection* _collection) {
if ( materialNode() == NULL) if ( materialNode() == NULL)
std::cerr << "Error when creating Line Object! materialNode is NULL!" << std::endl; std::cerr << "Error when creating Line Object! materialNode is NULL!" << std::endl;
collectionNode_ = new ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection >(*collection_, materialNode() , "NEW LineNodeCollection"); collectionNode_ = new ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection >(*collection_, materialNode() , "NEW PolyLineCollection");
// Set default material of the polyLine // Set default material of the polyLine
materialNode()->set_random_color(); materialNode()->set_random_color();
...@@ -185,7 +186,7 @@ void PolyLineCollectionObject::init(PolyLineCollection* _collection) { ...@@ -185,7 +186,7 @@ void PolyLineCollectionObject::init(PolyLineCollection* _collection) {
void PolyLineCollectionObject::setName( QString _name ) { void PolyLineCollectionObject::setName( QString _name ) {
BaseObjectData::setName(_name); BaseObjectData::setName(_name);
std::string nodename = std::string("LineCollectionNode for LineCollection " + _name.toUtf8() ); std::string nodename = std::string("PolyLineCollectionNode for PolyLineCollection " + _name.toUtf8() );
collectionNode_->name( nodename ); collectionNode_->name( nodename );
} }
...@@ -193,8 +194,8 @@ void PolyLineCollectionObject::setName( QString _name ) { ...@@ -193,8 +194,8 @@ void PolyLineCollectionObject::setName( QString _name ) {
// Content // Content
// =============================================================================== // ===============================================================================
/** Get a pointer to the objects line. /** Get a pointer to the objects Collection.
* @return Pointer to the line * @return Pointer to the Collection
*/ */
PolyLineCollection* PolyLineCollectionObject::collection() { PolyLineCollection* PolyLineCollectionObject::collection() {
return collection_; return collection_;
...@@ -232,11 +233,6 @@ QString PolyLineCollectionObject::getObjectinfo() { ...@@ -232,11 +233,6 @@ QString PolyLineCollectionObject::getObjectinfo() {
output += "Object Contains PolyLineCollection : "; output += "Object Contains PolyLineCollection : ";
output += QString::number( collection()->n_polylines() ) + " polylines, "; output += QString::number( collection()->n_polylines() ) + " polylines, ";
/*output += QString::number( line()->n_edges() ) += " edges and is ";
if ( line()->is_closed() )
output += "closed.\n";
else
output += "open.\n";*/
output += "========================================================================\n"; output += "========================================================================\n";
return output; return output;
...@@ -264,57 +260,13 @@ bool PolyLineCollectionObject::pickingEnabled() { ...@@ -264,57 +260,13 @@ bool PolyLineCollectionObject::pickingEnabled() {
return collectionNode_->pickingEnabled(); return collectionNode_->pickingEnabled();
} }
/// Refine picking on triangle meshes /// Refine picking on poly line collections (!TODO)
ACG::Vec3d PolyLineCollectionObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget, ACG::Vec3d PolyLineCollectionObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget,
const ACG::Vec3d _hitPoint, const ACG::Vec3d _hitPoint,
const ACG::Vec3d _start , const ACG::Vec3d _start ,
const ACG::Vec3d _dir, const ACG::Vec3d _dir,
const unsigned int _targetIdx ) const size_t _targetIdx )
{ {
if ( _pickTarget == ACG::SceneGraph::PICK_FACE) {
//don't refine polyLine faces
return _hitPoint;
}
if ( _pickTarget == ACG::SceneGraph::PICK_EDGE) {
// TODO
// get picked edge handle
/* int eh;
eh = _targetIdx;
if(eh >= 0 && eh < (int)line()->n_edges())
{
//get vertices of the edge
ACG::Vec3d edgeStart = line()->point((eh+1)%line()->n_vertices());
ACG::Vec3d edgeEnd = line()->point(eh);
//retrieve the point on the edge that is closest to the backprojected hitpoint
ACG::Vec3d hitPointNew;
ACG::Geometry::distPointLineSquared(_hitPoint,edgeStart,edgeEnd,&hitPointNew);
}*/
return _hitPoint;
}
if ( _pickTarget == ACG::SceneGraph::PICK_VERTEX) {
// get picked vertex handle
/*int vh = _targetIdx;
if(vh>=0 && vh < (int)line()->n_vertices())
{
ACG::Vec3d hitpointNew = line()->point(vh);