From d4ac3b66a30e63f91dbc2b9beec21be93bac860e Mon Sep 17 00:00:00 2001
From: vahrenkamp <vahrenkamp@042f3d55-54a8-47e9-b7fb-15903f145c44>
Date: Wed, 5 Dec 2012 13:46:22 +0000
Subject: [PATCH] added ellipse drawing tools

git-svn-id: http://svn.code.sf.net/p/simox/code/trunk@347 042f3d55-54a8-47e9-b7fb-15903f145c44
---
 .../CoinVisualizationFactory.cpp              | 119 ++++++++++++++++++
 .../CoinVisualizationFactory.h                |  25 ++++
 2 files changed, 144 insertions(+)

diff --git a/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.cpp b/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.cpp
index 1d07d97c4..4351bc985 100644
--- a/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.cpp
+++ b/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.cpp
@@ -27,6 +27,8 @@
 #include <Inventor/nodes/SoMatrixTransform.h>
 #include <Inventor/nodes/SoMaterial.h>
 #include <Inventor/nodes/SoCone.h>
+#include <Inventor/nodes/SoRotationXYZ.h>
+#include <Inventor/nodes/SoScale.h>
 #include <Inventor/nodes/SoTransform.h>
 #include <Inventor/nodes/SoTranslation.h>
 #include <Inventor/nodes/SoBaseColor.h>
@@ -2106,6 +2108,123 @@ namespace VirtualRobot {
         return res;
     }
 
+	
+SoSeparator* CoinVisualizationFactory::CreateEllipse(float x, float y, float z, SoMaterial* matBody, bool showAxes, float axesHeight, float axesWidth, SoMaterial* matX, SoMaterial* matY, SoMaterial* matZ)
+{
+	// check for min size
+	float minSize = 1e-6f;
+	if (x<minSize)
+		x=minSize;
+	if (y<minSize)
+		y=minSize;
+	if (z<minSize)
+		z=minSize;
+
+	if (!matBody)
+	{
+		matBody = new SoMaterial;
+		matBody->diffuseColor.setValue(0.3f,0.6f,0.9f);
+		matBody->ambientColor.setValue(0.3f,0.6f,0.9f);
+		matBody->transparency.setValue(0.3f);
+	}
+	if (!matX)
+	{
+		matX = new SoMaterial;
+		matX->diffuseColor.setValue(1.0f,0.2f,0.2f);
+		matX->ambientColor.setValue(1.0f,0.2f,0.2f);
+		matX->transparency.setValue(0);
+	}
+	if (!matY)
+	{
+		matY = new SoMaterial;
+		matY->diffuseColor.setValue(0.2f,0.9f,0.2f);
+		matY->ambientColor.setValue(0.2f,0.9f,0.2f);
+		matY->transparency.setValue(0);
+	}
+	if (!matZ)
+	{
+		matZ = new SoMaterial;
+		matZ->diffuseColor.setValue(0.2f,0.2f,0.9f);
+		matZ->ambientColor.setValue(0.2f,0.2f,0.9f);
+		matZ->transparency.setValue(0);
+	}
+	SoSeparator *result = new SoSeparator;
+	result->ref();
+
+	// ensure good quality
+	SoComplexity *c = new SoComplexity();
+	c->type.setValue(SoComplexity::OBJECT_SPACE);
+	c->value.setValue(1.0f);
+	result->addChild(c);
+
+
+	SoSeparator *p1 = new SoSeparator;
+	result->addChild(p1);
+
+	p1->addChild(matBody);
+	SoScale *sc1 = new SoScale;
+	sc1->scaleFactor.setValue(x,y,z);
+	p1->addChild(sc1);
+	
+	SoSphere *sp = new SoSphere();
+	sp->radius.setValue(1.0f);
+	p1->addChild(sp);
+
+	if (showAxes)
+	{
+
+		// y axis
+		SoSeparator *ax1 = new SoSeparator();
+		result->addChild(ax1);
+		ax1->addChild(c);
+		SoScale *scAx1 = new SoScale();
+		scAx1->scaleFactor.setValue(x+axesHeight,1.0f,z+axesHeight);
+		ax1->addChild(scAx1);
+		ax1->addChild(matY);
+		SoCylinder *c1 = new SoCylinder();
+		c1->radius.setValue(1.0f);
+		c1->height.setValue(axesWidth); // cone is aligned with y axis
+		ax1->addChild(c1);
+
+		// z axis
+		SoSeparator *ax2 = new SoSeparator();
+		result->addChild(ax2);
+		ax2->addChild(c);
+		SoScale *scAx2 = new SoScale();
+		scAx2->scaleFactor.setValue(x+axesHeight,y+axesHeight,1.0f);
+		ax2->addChild(scAx2);
+		ax2->addChild(matZ);
+		SoRotationXYZ *rot2 = new SoRotationXYZ();
+		rot2->axis.setValue(SoRotationXYZ::X);
+		rot2->angle.setValue(float(M_PI*0.5f));
+		ax2->addChild(rot2);
+		SoCylinder *c2 = new SoCylinder();
+		c2->radius.setValue(0.999f); // avoid artefacts at meeting points with other axes
+		c2->height.setValue(axesWidth); 
+		ax2->addChild(c2);
+
+		// x axis
+		SoSeparator *ax3 = new SoSeparator();
+		result->addChild(ax3);
+		ax3->addChild(c);
+		SoScale *scAx3 = new SoScale();
+		scAx3->scaleFactor.setValue(1.0f,y+axesHeight,z+axesHeight);
+		ax3->addChild(scAx3);
+		ax3->addChild(matX);
+		SoRotationXYZ *rot3 = new SoRotationXYZ();
+		rot3->axis.setValue(SoRotationXYZ::Z);
+		rot3->angle.setValue(float(-M_PI*0.5f));
+		ax3->addChild(rot3);
+		SoCylinder *c3 = new SoCylinder();
+		c3->radius.setValue(0.998f); // avoid artefacts at meeting points with other axes
+		c3->height.setValue(axesWidth); 
+		ax3->addChild(c3);
+	}
+
+	result->unrefNoDelete();
+	return result;
+}
+
 
 
 } // namespace VirtualRobot
diff --git a/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h b/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h
index 146a755b4..b97075c0a 100644
--- a/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h
+++ b/VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h
@@ -34,6 +34,7 @@
 
 #include <Inventor/SoInput.h>
 #include <Inventor/nodes/SoMatrixTransform.h>
+#include <Inventor/nodes/SoMaterial.h>
 #include <Inventor/SoOffscreenRenderer.h>
 #include <Inventor/nodes/SoPerspectiveCamera.h>
 #include <Inventor/nodes/SoCamera.h>
@@ -96,6 +97,30 @@ public:
 	static SoSeparator* CreatePointsVisualization(const std::vector<MathTools::ContactPoint> &points, bool showNormals = false);
 	static SoSeparator* CreateArrow(const Eigen::Vector3f &n, float length = 50.0f, float width = 2.0f, const Color &color = Color::Gray());
 	static SoSeparator* CreateVertexVisualization( const Eigen::Vector3f &position, float radius, float transparency, float colorR = 0.5f, float colorG = 0.5f, float colorB = 0.5f );
+	
+	/*! 
+		Creates an coordinate axis aligned ellipse
+		\param x The extend in x direction must be >= 1e-6
+		\param y The extend in y direction must be >= 1e-6
+		\param z The extend in z direction must be >= 1e-6
+		\param matBody If not given a standard material is used for the ellipse body
+		\param showAxes If true, the axes are visualized
+		\param axesHeight The height of the axes (measured from the body surface)
+		\param axesWidth The width of the axes.
+		\param matAxisX If not given a standard material is used for axis X
+		\param matAxisY If not given a standard material is used for axis Y
+		\param matAxisZ If not given a standard material is used for axis Z
+		\return A separator conatining the visualization.
+	*/
+	static SoSeparator* CreateEllipse(	float x, float y, float z, 
+										SoMaterial* matBody = NULL, 
+										bool showAxes = true, 
+										float axesHeight = 4.0f, 
+										float axesWidth = 8.0f, 
+										SoMaterial* matAxisX = NULL,
+										SoMaterial* matAxisY = NULL,
+										SoMaterial* matAxisZ = NULL
+										);
 
 	static SoSeparator* CreateOOBBVisualization( const MathTools::OOBB& oobb, Color colorLine = Color::Gray(), float lineSize = 4.0f);
 	static SoSeparator* CreateSegmentVisualization( const MathTools::Segment& s, Color colorLine = Color::Gray(), float lineSize = 4.0f);
-- 
GitLab