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

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"
This diff is collapsed.
/*===========================================================================*\
* *
* 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$ *
* *
\*===========================================================================*/
#ifndef POLYLINE_COLLECTION_NODE_T_HH
#define POLYLINE_COLLECTION_NODE_T_HH
//== INCLUDES =================================================================
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/IRenderer.hh>
#include <ACG/GL/GLPrimitives.hh>
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== CLASS DEFINITION =========================================================
/** \class PolyLineNodeT PolyLineCollectionNodeT.hh <ACG/.../PolyLineCollectionNodeT.hh>
This Node provides support for rendering polyline collections.
*/
template <class PolyLineCollection>
class PolyLineCollectionNodeT : public BaseNode
{
public:
// typedefs for easy access
typedef typename PolyLineCollection::PolyLine::Point Point;
/// Constructor
PolyLineCollectionNodeT(PolyLineCollection& _pl, BaseNode* _parent = 0, std::string _name = "<PolyLineCollectionNode>");
/// Destructor
virtual ~PolyLineCollectionNodeT() {}
PolyLineCollection& polyline_collection() { return polyline_collection_; }
/// static name of this class
ACG_CLASSNAME(PolyLineCollectionNodeT);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// draw lines and normals
void draw(GLState& /*_state*/,const DrawModes::DrawMode& _drawMode);
/// picking
void pick(GLState& _state, PickTarget _target);
/** \brief Add the objects to the given renderer
*
* @param _renderer The renderer which will be used. Add your geometry into this class
* @param _state The current GL State when this object is called
* @param _drawMode The active draw mode
* @param _mat Current material
*/
void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
/// Trigger an update of the vbo
void update() { updateVBO_ = true; };
private:
/// Copy constructor (not used)
PolyLineCollectionNodeT(const PolyLineCollectionNodeT& _rhs);
/// Assignment operator (not used)
PolyLineCollectionNodeT& operator=(const PolyLineCollectionNodeT& _rhs);
/// Buffer organization
ACG::VertexDeclaration vertexDecl_;
/** \brief Trigger an update of the vbo
*
* If the polyLineCollection is changed, you have to call this function to update the buffers.
*
*/
void updateVBO();
/** \brief Write vertex data for rendering to a buffer
*
* @param _vertex index of polyline vertex
* @param _dst address of vertex in buffer
*/
void writeVertex(typename PolyLineCollection::PolyLine* _polyline, unsigned int _vertex, void* _dst);
private:
/// The associated poly line collection
PolyLineCollection& polyline_collection_;
/// VBO used to render the poly line
unsigned int vbo_;
/// Flag to trigger update of vbo
bool updateVBO_;
/// Sphere for VertexSphere DrawMode
GLSphere* sphere_;
std::vector<std::pair<size_t, size_t> > offsets_;
size_t total_vertex_count_;
};
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(ACG_POLYLINECOLLECTIONNODET_C)
#define ACG_POLYLINECOLLECTIONNODET_TEMPLATES
#include "PolyLineCollectionNodeT.cc"
#endif
#endif // POLYLINE_COLLECTION_NODE_T_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$ *