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

Merge branch 'polyline_collection' into 'master'

Polyline collection

closes #34

See merge request !181
parents 3fe68691 9f34320d
Pipeline #3354 passed with stage
in 35 minutes and 59 seconds
/* ========================================================================= *
* *
* 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. *
* *
* ========================================================================= */
/*===========================================================================*\
*
* $Revision$
* $Date$
*
\*===========================================================================*/
//=============================================================================
//
// Plugin Functions for Polyline Collections
//
//=============================================================================
#include <OpenFlipper/common/Types.hh>
#include "PolyLineCollection.hh"
#include "PluginFunctionsPolyLineCollection.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
namespace PluginFunctions {
// ===============================================================================
// Get source polylines
// ===============================================================================
bool getSourcePolylineCollections( std::vector<PolyLineCollection*>& _polylines )
{
_polylines.clear();
for ( ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS,DATA_POLY_LINE_COLLECTION ) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
_polylines.push_back ( PluginFunctions::polyLineCollection( *o_it ) );
if( _polylines.back() == 0)
std::cerr << "ERROR: Polyine get_source_polyline_collections fatal error\n";
}
return ( !_polylines.empty() );
}
// ===============================================================================
// Get target polylines
// ===============================================================================
bool getTargetPolylines( std::vector<PolyLineCollection*>& _polylines )
{
_polylines.clear();
for ( ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_POLY_LINE_COLLECTION ) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
_polylines.push_back ( PluginFunctions::polyLineCollection( *o_it ) );
if( _polylines.back() == 0)
std::cerr << "ERROR: Polyine getTargetPolylines fatal error\n";
}
return ( !_polylines.empty() );
}
// ===============================================================================
// Get objects
// ===============================================================================
bool getObject( int _identifier , PolyLineCollectionObject*& _object ) {
/*if ( _identifier == BaseObject::NOOBJECT ) {
_object = 0;
return false;
}*/
// Get object by using the map accelerated plugin function
BaseObjectData* object = 0;
PluginFunctions::getObject(_identifier,object);
_object = dynamic_cast< PolyLineCollectionObject* >(object);
return ( _object != 0 );
}
// ===============================================================================
// Getting data from objects and casting between them
// ===============================================================================
PolyLineCollection* polyLineCollection( BaseObjectData* _object ) {
if ( _object->dataType(DATA_POLY_LINE_COLLECTION) ) {
PolyLineCollectionObject* object = dynamic_cast< PolyLineCollectionObject* >(_object);
return object->collection();
} else
return 0;
}
PolyLineCollectionObject* polyLineCollectionObject( BaseObjectData* _object ) {
if ( ! _object->dataType(DATA_POLY_LINE_COLLECTION) )
return 0;
return dynamic_cast< PolyLineCollectionObject* >( _object );
}
PolyLineCollectionObject* polyLineCollectionObject( int _objectId ) {
// Get object by using the map accelerated plugin function
BaseObjectData* object = 0;
PluginFunctions::getObject(_objectId,object);
if ( object == 0 )
return 0;
PolyLineCollectionObject* meshObject = dynamic_cast< PolyLineCollectionObject* >(object);
return meshObject;
}
}
/* ========================================================================= *
* *
* 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. *
* *
* ========================================================================= */
/*===========================================================================*\
*
* $Revision$
* $Date$
*
\*===========================================================================*/
//=============================================================================
//
// Standard Functions
//
//=============================================================================
/**
* \file PluginFunctionsPolyLineCollection.hh
* This file contains functions which can be used by plugins to access Polyline Collections in the framework.
*/
#pragma once
#include <OpenFlipper/common/Types.hh>
#include "PolyLineCollectionTypes.hh"
#include "PolyLineCollectionObject.hh"
/** The Namespace PluginFunctions contains functions for all plugins. */
namespace PluginFunctions {
/** \brief Get a pointer to every Polyline Collection which is marked as a source.
*
* @param _polylines ( vector returning the source Polyline Collections )
* @return false, if no PolylineCollection is selected as source
*/
DLLEXPORT
bool getSourcePolylineCollections( std::vector<PolyLineCollection*>& _polylines );
/** \brief Get a pointer to every Polyline Collection which is marked as a target.
*
* @param _polylines ( vector returning the target Polyline Collections )
* @return false, if no PolylineCollection is selected as target
*/
DLLEXPORT
bool getTargetPolylineCollections( std::vector<PolyLineCollection*>& _polylines );
/** This functions returns the object with the given id if it is a Polyline Collection.
* See get_object( int _identifier , BaseObject*& _object ) for more details.
*/
DLLEXPORT
bool getObject( int _identifier , PolyLineCollectionObject*& _object );
/** \brief Get a polyLine Collection from an object.
*
* @param _object The object should be of type BaseDataObject. If the content is a Polyline Collection, a
* Polyline Collection will be returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
PolyLineCollection* polyLineCollection( BaseObjectData* _object );
/** \brief Cast an BaseObject to a Polyline Collection Object if possible
*
* @param _object The object should be of type BaseDataObject. If the content is a Polyline Collection, a
* a Polyline Collection Object is returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
PolyLineCollectionObject* polyLineCollectionObject( BaseObjectData* _object );
/** \brief Get an Polyline Collection Object from the given id If possible
*
* @param _objectId Id of the requested Object. If the content is a Polyline Collection,
* a Polyline Collection Object is returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
PolyLineCollectionObject* polyLineCollectionObject( int _objectId );
}
/*===========================================================================*\
* *
* 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. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// PolyLineCollectionsTypes
//
//=============================================================================
/**
* \file PolyLineCollection.hh
* This File contains all required includes for using PolyLine Collections
*/
#pragma once
//== INCLUDES =================================================================
/** \def DATA_POLY_LINE_COLLECTION
* Use this macro to reference polygonal lines
*/
#define DATA_POLY_LINE_COLLECTION typeId("PolyLineCollection")
#include "ObjectTypes/PolyLine/PolyLineObject.hh"
#include "PluginFunctionsPolyLineCollection.hh"
#include "PolyLineCollectionTypes.hh"
#include "PolyLineCollectionObject.hh"
/*===========================================================================*\
* *
* 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. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS PolyLineNodeT - IMPLEMENTATION
//
//=============================================================================
#define ACG_POLYLINECOLLECTIONNODET_C
//== INCLUDES =================================================================
#include "PolyLineCollectionNodeT.hh"
#include <ACG/GL/gl.hh>
#include <ACG/Utils/VSToolsT.hh>
#include <vector>
#include <OpenMesh/Core/Utils/vector_cast.hh>
#ifdef _WIN32
#include <cstdint>
#else
#include <stdint.h>
#endif
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
/// Constructor
template <class PolyLineCollection>
PolyLineCollectionNodeT<PolyLineCollection>::PolyLineCollectionNodeT(PolyLineCollection& _pl, BaseNode* _parent, std::string _name) :
BaseNode(_parent, _name),
polyline_collection_(_pl),
vbo_(0),
updateVBO_(true),
sphere_(0),
total_vertex_count_(0)
{
// Initial default draw mode
drawMode(DrawModes::WIREFRAME | DrawModes::POINTS );
}
//----------------------------------------------------------------------------
template <class PolyLineCollection>
void
PolyLineCollectionNodeT<PolyLineCollection>::
boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
{
for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
typename PolyLineCollection::PolyLine* polyline = *it;
if(polyline){
for (unsigned int i=0; i< polyline->n_vertices(); ++i)
{
_bbMin.minimize(polyline->point(i));
_bbMax.maximize(polyline->point(i));
}
}
}
}
//----------------------------------------------------------------------------
template <class PolyLineCollection>
DrawModes::DrawMode
PolyLineCollectionNodeT<PolyLineCollection>::
availableDrawModes() const
{
return (DrawModes::WIREFRAME | DrawModes::POINTS );
}
//----------------------------------------------------------------------------
template <class PolyLineCollection>
void
PolyLineCollectionNodeT<PolyLineCollection>::
draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
{
// Block if we do not have any polylines
if ( polyline_collection_.n_polylines() == 0 )
return;
// Update the vbo only if required.
if ( updateVBO_ )
updateVBO();
ACG::GLState::disable(GL_LIGHTING);
ACG::GLState::disable(GL_TEXTURE_2D);
// Bind the vertex array
ACG::GLState::bindBuffer(GL_ARRAY_BUFFER_ARB, vbo_);
vertexDecl_.activateFixedFunction();
ACG::Vec4f color = _state.ambient_color() + _state.diffuse_color();
// draw points
if (_drawMode & DrawModes::POINTS)
{
_state.set_color( color );
// Draw all vertices (don't care about selection)
for(typename PolyLineCollection::index_iterator it = polyline_collection_.visible_iter(); it; ++it){
typename PolyLineCollection::PolyLine* polyline = *it;
if(polyline && polyline->n_vertices() > 0){
glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
}
}
glDisableClientState(GL_COLOR_ARRAY);
float point_size_old = _state.point_size();
_state.set_point_size(point_size_old+4.0f);
_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){
typename PolyLineCollection::PolyLine* polyline = *it;
if(polyline && polyline->n_vertices() > 0){
glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
}
}
_state.set_point_size(point_size_old);
glEnableClientState(GL_COLOR_ARRAY);
}
// draw line segments
if (_drawMode & DrawModes::WIREFRAME) {
_state.set_color( color );
for(typename PolyLineCollection::index_iterator it = polyline_collection_.visible_iter(); it; ++it){
typename PolyLineCollection::PolyLine* polyline = *it;
if(polyline && polyline->n_vertices() > 0){
if ( polyline->is_closed() ){
glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
}else{
glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
}
}
}
glDisableClientState(GL_COLOR_ARRAY);
float line_width_old = _state.line_width();
_state.set_color(Vec4f(1, 0, 0, 1));
_state.set_line_width(2 * line_width_old);
for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){
typename PolyLineCollection::PolyLine* polyline = *it;
if(polyline && polyline->n_vertices() > 0){
if ( polyline->is_closed() ){