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

Cleanup the Objecttypes and nodes

parent 0c1aa62b
Pipeline #3346 passed with stage
in 40 minutes and 2 seconds
......@@ -54,17 +54,16 @@
//=============================================================================
/**
* \file PolyLine.hh
* This File contains all required includes for using Poly Line Collections
* \file PolyLineCollection.hh
* This File contains all required includes for using PolyLine Collections
*/
#ifndef POLYLINE_COLLECTION_INCLUDE_HH
#define POLYLINE_COLLECTION_INCLUDE_HH
#pragma once
//== INCLUDES =================================================================
/** \def DATA_POLY_LINE
/** \def DATA_POLY_LINE_COLLECTION
* Use this macro to reference polygonal lines
*/
#define DATA_POLY_LINE_COLLECTION typeId("PolyLineCollection")
......@@ -75,4 +74,3 @@
#include "PolyLineCollectionObject.hh"
#endif // POLYLINE_COLLECTION_INCLUDE_HH
\ No newline at end of file
......@@ -88,7 +88,8 @@ PolyLineCollectionNodeT<PolyLineCollection>::PolyLineCollectionNodeT(PolyLineCol
polyline_collection_(_pl),
vbo_(0),
updateVBO_(true),
sphere_(0)
sphere_(0),
total_vertex_count_(0)
{
// Initial default draw mode
......@@ -172,7 +173,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
float point_size_old = _state.point_size();
_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
for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){
......@@ -234,7 +235,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
if(polyline){
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){
continue;
}
......@@ -267,7 +268,7 @@ void
PolyLineCollectionNodeT<PolyLineCollection>::
pick(GLState& _state, PickTarget _target)
{
// TODO
if ( polyline_collection_.n_polylines() == 0 )
return;
......@@ -331,39 +332,9 @@ void
PolyLineCollectionNodeT<PolyLineCollection>::
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;
if(int(offsets_.size()) != polyline_collection_.n_polylines() ){
if( offsets_.size() != polyline_collection_.n_polylines() ){
offsets_.resize(polyline_collection_.n_polylines());
lines_did_change = true;
}
......@@ -371,10 +342,10 @@ updateVBO() {
int offset = 0;
total_vertex_count_ = 0;
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;
if(*it){
current_offset.second = int(it->n_vertices()) + 1;
current_offset.second = it->n_vertices() + 1;
}else{
current_offset.second = 0;
}
......@@ -398,49 +369,16 @@ updateVBO() {
vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION);
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
if (!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
unsigned int bufferSize = vertexDecl_.getVertexStride() * offset;
// Create the required array
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){
typename PolyLineCollection::PolyLine* polyline = *it;
......@@ -527,7 +465,7 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Viewport size
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;
const ACG::SceneGraph::DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
......@@ -552,15 +490,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Point Size geometry shader
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!)
ro.debugName = "polylinecollection.Points";
localMaterial.baseColor(defaultColor);
......@@ -589,16 +518,6 @@ getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::S
// Line Width geometry shader
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";
localMaterial.baseColor(defaultColor);
ro.setMaterial(&localMaterial);
......@@ -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 ACG
......
......@@ -71,11 +71,9 @@ namespace SceneGraph {
/** \class PolyLineNodeT PolyLineNodeT.hh <ACG/.../PolyLineNodeT.hh>
/** \class PolyLineNodeT PolyLineCollectionNodeT.hh <ACG/.../PolyLineCollectionNodeT.hh>
Brief Description.
A more elaborate description follows.
This Node provides support for rendering polyline collections.
*/
template <class PolyLineCollection>
......@@ -121,11 +119,6 @@ public:
/// Trigger an update of the vbo
void update() { updateVBO_ = true; };
void reset_vbo(){
offsets_.clear();
updateVBO_ = true;
}
private:
/// Copy constructor (not used)
......@@ -139,7 +132,7 @@ private:
/** \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();
......@@ -153,7 +146,7 @@ private:
private:
/// The associated poly line
/// The associated poly line collection
PolyLineCollection& polyline_collection_;
/// VBO used to render the poly line
......@@ -165,9 +158,9 @@ private:
/// Sphere for VertexSphere DrawMode
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 @@
//== CLASS DEFINITION =========================================================
/** Constructor for PolyLine Objects. This object class gets a Separator Node giving
* the root node to which it should be connected. The line is generated internally
/** Constructor for PolyLine Collection Objects. This object class gets a Separator Node giving
* 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
* You dont need to create an object of this type manually. Use
* PluginFunctions::addPolyLine instead. ( see Types.hh::DataType )
* You don't need to create an object of this type manually. Use
* PluginFunctions::addPolyLineCollection instead. ( see Types.hh::DataType )
*/
PolyLineCollectionObject::PolyLineCollectionObject() :
BaseObjectData( ),
......@@ -96,8 +96,8 @@ PolyLineCollectionObject::PolyLineCollectionObject(const PolyLineCollectionObjec
setName( name() );
}
/** Destructor for PolyLine Objects. The destructor deletes the Line and all
* Scenegraph nodes associated with the Line or the object.
/** Destructor for PolyLineCollection Objects. The destructor deletes the Collection and all
* Scenegraph nodes associated with the Collection or the object.
*/
PolyLineCollectionObject::~PolyLineCollectionObject()
{
......@@ -108,7 +108,7 @@ PolyLineCollectionObject::~PolyLineCollectionObject()
// perObjectData.
deleteData();
// Delete the Mesh only, if this object contains a mesh
// Delete the collection only, if this object contains a collection
if ( collection_ != NULL) {
delete collection_;
collection_ = NULL;
......@@ -116,15 +116,16 @@ PolyLineCollectionObject::~PolyLineCollectionObject()
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;
}
/** Cleanup Function for Line Objects. Deletes the contents of the whole object and
* calls PolyLineObject::init afterwards.
/** Cleanup Function for Collection Objects. Deletes the contents of the whole object and
* calls PolyLineCollection::init afterwards.
*/
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) {
delete collection_;
collection_ = NULL;
......@@ -150,8 +151,8 @@ BaseObject* PolyLineCollectionObject::copy() {
return dynamic_cast< BaseObject* >(object);
}
/** This function initalizes the line object. It creates the scenegraph nodes,
* the line.
/** This function initializes the Collection object. It creates the scenegraph nodes,
* the Collection.
*/
void PolyLineCollectionObject::init(PolyLineCollection* _collection) {
......@@ -165,7 +166,7 @@ void PolyLineCollectionObject::init(PolyLineCollection* _collection) {
if ( materialNode() == NULL)
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
materialNode()->set_random_color();
......@@ -185,7 +186,7 @@ void PolyLineCollectionObject::init(PolyLineCollection* _collection) {
void PolyLineCollectionObject::setName( QString _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 );
}
......@@ -193,8 +194,8 @@ void PolyLineCollectionObject::setName( QString _name ) {
// Content
// ===============================================================================
/** Get a pointer to the objects line.
* @return Pointer to the line
/** Get a pointer to the objects Collection.
* @return Pointer to the Collection
*/
PolyLineCollection* PolyLineCollectionObject::collection() {
return collection_;
......@@ -232,11 +233,6 @@ QString PolyLineCollectionObject::getObjectinfo() {
output += "Object Contains PolyLineCollection : ";
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";
return output;
......@@ -264,57 +260,13 @@ bool PolyLineCollectionObject::pickingEnabled() {
return collectionNode_->pickingEnabled();
}
/// Refine picking on triangle meshes
/// Refine picking on poly line collections (!TODO)
ACG::Vec3d PolyLineCollectionObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget,
const ACG::Vec3d _hitPoint,
const ACG::Vec3d _start ,
const ACG::Vec3d _dir,
const unsigned int _targetIdx )
const ACG::Vec3d _hitPoint,
const ACG::Vec3d _start ,
const ACG::Vec3d _dir,
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);
//just return the vertex position
return hitpointNew;
}*/
return _hitPoint;
}
return _hitPoint;
}
......
......@@ -58,9 +58,7 @@
* This File contains the PolyLine Object
*/
#ifndef POLYLINE_COLLECTION_OBJECT_HH
#define POLYLINE_COLLECTION_OBJECT_HH
#pragma once
......@@ -77,7 +75,7 @@
//== CLASS DEFINITION =========================================================
/** This class provides the functionality for all kind of meshes for the framework
/** This class provides the functionality for all kind of polyline collections for the framework
*/
class DLLEXPORT PolyLineCollectionObject : public BaseObjectData {
public:
......@@ -104,14 +102,9 @@ class DLLEXPORT PolyLineCollectionObject : public BaseObjectData {
*/
BaseObject* copy();
void reset_vbo(){
collectionNode()->reset_vbo();
}
protected:
/// Initialise current object, including all related nodes.
/// Initialize current object, including all related nodes.
virtual void init(PolyLineCollection* _collection = 0);
//===========================================================================
......@@ -197,11 +190,9 @@ class DLLEXPORT PolyLineCollectionObject : public BaseObjectData {
const ACG::Vec3d _hitPoint,
const ACG::Vec3d _start ,
const ACG::Vec3d _dir,
const unsigned int _targetIdx );
const size_t _targetIdx );
/** @} */
};
#endif // POLYLINE_COLLECTION_OBJECT_HH
\ No newline at end of file
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#pragma once
#include <ObjectTypes/PolyLine/PolyLineT.hh>
......@@ -43,7 +84,7 @@ public:
};
struct index_iterator{
index_iterator(std::vector<PolyLine*>& _lines, typename std::vector<int>::iterator _begin, typename std::vector<int>::iterator _end) :
index_iterator(std::vector<PolyLine*>& _lines, typename std::vector<size_t>::iterator _begin, typename std::vector<size_t>::iterator _end) :
lines_(_lines),
it_(_begin),
end_(_end)
......@@ -70,39 +111,57 @@ public:
}
std::vector<PolyLine*>& lines_;
typename std::vector<int>::iterator it_;
typename std::vector<int>::iterator end_;
typename std::vector<size_t>::iterator it_;
typename std::vector<size_t>::iterator end_;
};
public:
/** \brief Destructor
*
* The destructor will call delete on all PolyLines in the PolyLine Collection!
*/
virtual ~PolyLineCollectionT(){
int n = poly_lines_.size();
for(int i = 0; i < n; ++i){
const size_t n = poly_lines_.size();
for(size_t i = 0; i < n; ++i){
delete poly_lines_[i];
}
}
// Create a new polyline in the collection
int add_poly_line(PolyLine* _poly_line){
/** Create a new polyline in the collection
*
* @param _poly_line The new polyline to be added to the collection
* @return Index of the new polyline in the collection
*/
size_t add_poly_line(PolyLine* _poly_line){
int new_idx;
;
if(empty_slots_.empty()){
new_idx = poly_lines_.size();
poly_lines_.push_back(0);
}else{
new_idx = empty_slots_.front();