Skip to content

Commit

Permalink
- add own shape type for pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and adeas31 committed Sep 30, 2016
1 parent 394cc91 commit 610825c
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 29 deletions.
132 changes: 132 additions & 0 deletions OMEdit/OMEditGUI/Animation/ExtraShapes.cpp
@@ -0,0 +1,132 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Volker Waurich <volker.waurich@tu-dresden.de>
*/

#include "ExtraShapes.h"
#include <iostream>

Pipecylinder::Pipecylinder(float rI, float rO, float l) :
osg::Geometry()
{
const int nEdges = 20;
double phi = 2 * M_PI/nEdges;

//VERTICES
osg::Vec3Array* vertices = new osg::Vec3Array;
// inner base ring
for (int i = 0; i < nEdges; i++) {
vertices->push_back(osg::Vec3(sin(phi*i)*rI, cos(phi*i)*rI, 0));
}
// outer base ring
for (int i = 0; i < nEdges; i++) {
vertices->push_back(osg::Vec3(sin(phi*i)*rO, cos(phi*i)*rO, 0));
}
// inner end ring
for (int i = 0; i < nEdges; i++) {
vertices->push_back(osg::Vec3(sin(phi*i)*rI, cos(phi*i)*rI, l));
}
// outer end ring
for (int i = 0; i < nEdges; i++) {
vertices->push_back(osg::Vec3(sin(phi*i)*rO, cos(phi*i)*rO, l));
}
this->setVertexArray(vertices);

//PLANES
// base plane bottom
osg::DrawElementsUInt* basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(0);
basePlane->push_back(nEdges-1);
basePlane->push_back(2*nEdges-1);
basePlane->push_back(nEdges);
this->addPrimitiveSet(basePlane);

for (int i = 0; i < (nEdges-1); i++) {
basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(0 + i);
basePlane->push_back(1 + i);
basePlane->push_back(nEdges +1 +i);
basePlane->push_back(nEdges + 0 + i);
this->addPrimitiveSet(basePlane);
}

// base plane top
basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(0+2*nEdges);
basePlane->push_back(nEdges - 1 + 2 * nEdges);
basePlane->push_back(2 * nEdges - 1 + 2 * nEdges);
basePlane->push_back(nEdges + 2 * nEdges);
this->addPrimitiveSet(basePlane);

for (int i = (2 * nEdges); i < (nEdges - 1 + (2 * nEdges)); i++) {
basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(0 + i);
basePlane->push_back(1 + i);
basePlane->push_back(nEdges + 1 + i);
basePlane->push_back(nEdges + 0 + i);
this->addPrimitiveSet(basePlane);
}

//inner lateral planes
basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(0);
basePlane->push_back(nEdges - 1);
basePlane->push_back(3 * nEdges-1);
basePlane->push_back(2 * nEdges);
this->addPrimitiveSet(basePlane);

for (int i = 0; i < (nEdges - 1); i++) {
basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(i);
basePlane->push_back(i+1);
basePlane->push_back(i + 1 + 2*nEdges);
basePlane->push_back(i + 2*nEdges);
this->addPrimitiveSet(basePlane);
}
//outer lateral planes
basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(nEdges);
basePlane->push_back(2*nEdges - 1);
basePlane->push_back(4 * nEdges-1);
basePlane->push_back(3 * nEdges);
this->addPrimitiveSet(basePlane);

//outer lateral planes
for (int i = nEdges; i < (2*nEdges - 1); i++) {
basePlane = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
basePlane->push_back(i);
basePlane->push_back(i + 1);
basePlane->push_back(i + 1 + 2 * nEdges);
basePlane->push_back(i + 2 * nEdges);
this->addPrimitiveSet(basePlane);
}
}
53 changes: 53 additions & 0 deletions OMEdit/OMEditGUI/Animation/ExtraShapes.h
@@ -0,0 +1,53 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Volker Waurich <volker.waurich@tu-dresden.de>
*/

#ifndef EXTRASHAPES_H
#define EXTRASHAPES_H

#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Shape>

class Pipecylinder : public osg::Geometry
{
public:
Pipecylinder(float rI, float rO, float l);
~Pipecylinder() {};
};



#endif //end EXTRASHAPES_H
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Animation/Shapes.cpp
Expand Up @@ -63,6 +63,7 @@ ShapeObject::ShapeObject()
_width(ShapeObjectAttribute(0.1)),
_height(ShapeObjectAttribute(0.1)),
_specCoeff(ShapeObjectAttribute(0.7)),
_extra(ShapeObjectAttribute(0.0)),
_mat(osg::Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0))
{
_r[0] = ShapeObjectAttribute(0.1);
Expand Down Expand Up @@ -110,6 +111,8 @@ void ShapeObject::dumpVisAttributes() const
std::cout << " " << _mat(1, 0) << ", " << _mat(1, 1) << ", " << _mat(1, 2) << ", " << _mat(1, 3) << std::endl;
std::cout << " " << _mat(2, 0) << ", " << _mat(2, 1) << ", " << _mat(2, 2) << ", " << _mat(2, 3) << std::endl;
std::cout << " " << _mat(3, 0) << ", " << _mat(3, 1) << ", " << _mat(3, 2) << ", " << _mat(3, 3) << std::endl;
std::cout << "extra " << _extra.getValueString() << std::endl;

}


Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Animation/Shapes.h
Expand Up @@ -81,6 +81,7 @@ class ShapeObject
ShapeObjectAttribute _T[9];
ShapeObjectAttribute _specCoeff;
osg::Matrix _mat;
ShapeObjectAttribute _extra;
};

struct rAndT
Expand Down
23 changes: 14 additions & 9 deletions OMEdit/OMEditGUI/Animation/Visualizer.cpp
Expand Up @@ -166,6 +166,9 @@ void OMVisualBase::initVisObjects()
expNode = shapeNode->first_node((const char*) "specCoeff")->first_node();
shape._specCoeff = getObjectAttributeForNode(expNode);

expNode = shapeNode->first_node((const char*) "extra")->first_node();
shape._extra = getObjectAttributeForNode(expNode);

_shapes.push_back(shape);
}
} // end for-loop
Expand Down Expand Up @@ -455,8 +458,10 @@ void UpdateVisitor::apply(osg::Geode& node)
//osg::ref_ptr<osg::ShapeDrawable> shapeDraw = dynamic_cast<osg::ShapeDrawable*>(draw.get());
//shapeDraw->setColor(osg::Vec4(visAttr.color,1.0));

if (_shape._type == "pipecylinder")
draw->setShape(new osg::Cylinder(osg::Vec3f(0.0, 0.0, 0.0), _shape._width.exp / 2.0, _shape._length.exp));
if (_shape._type == "pipe")
draw = (new Pipecylinder((_shape._width.exp * _shape._extra.exp )/2 , (_shape._width.exp)/2, _shape._length.exp))->asDrawable();
else if (_shape._type == "pipecylinder")
draw = (new Pipecylinder((_shape._width.exp * _shape._extra.exp )/2 , (_shape._width.exp)/2, _shape._length.exp))->asDrawable();
else if (_shape._type == "cylinder")
draw->setShape(new osg::Cylinder(osg::Vec3f(0.0, 0.0, 0.0), _shape._width.exp / 2.0, _shape._length.exp));
else if (_shape._type == "box")
Expand All @@ -467,7 +472,7 @@ void UpdateVisitor::apply(osg::Geode& node)
draw->setShape(new osg::Sphere(osg::Vec3f(0.0, 0.0, 0.0), _shape._length.exp / 2.0));
else
{
std::cout<<"Unknown type, we make a capsule."<<std::endl;
std::cout<<"Unknown type "<<_shape._type<<", we make a capsule."<<std::endl;
//string id = string(visAttr.type.begin(), visAttr.type.begin()+11);
draw->setShape(new osg::Capsule(osg::Vec3f(0.0, 0.0, 0.0), 0.1, 0.5));
}
Expand Down Expand Up @@ -627,12 +632,6 @@ rAndT rotateModelica2OSG(osg::Vec3f r, osg::Vec3f r_shape, osg::Matrix3 T, osg::

if (type == "cylinder")
{
/*
r = r + r_shape;
r_offset = dirs.lDir*length/2.0;
r_offset = V3mulMat3(r_offset,T);
res.r = r+r_offset;
*/
r_offset = dirs._lDir * length / 2.0;
res._r = V3mulMat3(r_shape + r_offset, T);
res._r = res._r + r;
Expand Down Expand Up @@ -667,6 +666,12 @@ rAndT rotateModelica2OSG(osg::Vec3f r, osg::Vec3f r_shape, osg::Matrix3 T, osg::
res._r = r;
//r_offset = dirs.lDir*length/2.0;
}
else if (type == "pipecylinder")
{
res._r = V3mulMat3(r_shape , T);
res._r = res._r + r;
res._T = Mat3mulMat3(T0, T);
}
else
{
r_offset = dirs._lDir * length / 2.0;
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Animation/Visualizer.h
Expand Up @@ -36,6 +36,7 @@
#define VISUALIZER_H

#include "AnimationUtil.h"
#include "ExtraShapes.h"
#include "rapidxml.hpp"
#include "Shapes.h"
#include "TimeManager.h"
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Animation/VisualizerMAT.cpp
Expand Up @@ -134,6 +134,7 @@ void VisualizerMAT::updateVisAttributes(const double time)
updateObjectAttributeMAT(&shape._color[2], time, tmpReaderPtr);

updateObjectAttributeMAT(&shape._specCoeff, time, tmpReaderPtr);
updateObjectAttributeMAT(&shape._extra, time, tmpReaderPtr);

rT = rotateModelica2OSG(osg::Vec3f(shape._r[0].exp, shape._r[1].exp, shape._r[2].exp),
osg::Vec3f(shape._rShape[0].exp, shape._rShape[1].exp, shape._rShape[2].exp),
Expand Down
20 changes: 0 additions & 20 deletions OMEdit/OMEditGUI/Animation/rapidxml.hpp
Expand Up @@ -6,26 +6,6 @@
// Revision $DateTime: 2009/05/13 01:46:17 $
//! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation

/*
* Copyright (C) 2016, Volker Waurich
*
* This file is part of OMVis.
*
* OMVis is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OMVis is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OMVis. If not, see <http://www.gnu.org/licenses/>.
*/


// If standard library is disabled, user must provide implementations of required functions and typedefs
#if !defined(RAPIDXML_NO_STDLIB)
#include <cstdlib> // For std::size_t
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -123,6 +123,7 @@ SOURCES += main.cpp \
Editors/MetaModelicaEditor.cpp \
Plotting/PlotWindowContainer.cpp \
Animation/AnimationWindowContainer.cpp \
Animation/ExtraShapes.cpp \
Animation/Visualizer.cpp \
Animation/VisualizerMAT.cpp \
Animation/Shapes.cpp \
Expand Down Expand Up @@ -193,6 +194,7 @@ HEADERS += Util/Helper.h \
D:/Programming/OPENMODELICA_GIT/OpenModelica/OMCompiler/3rdParty/FMIL/build/fmilib.h \
Animation/AnimationWindowContainer.h \
Animation/AnimationUtil.h \
Animation/ExtraShapes.h \
Animation/Visualizer.h \
Animation/VisualizerMAT.h \
Animation/Shapes.h \
Expand Down

0 comments on commit 610825c

Please sign in to comment.