void ShapeVisitor_VisualizerCreator::visualizeCylinder(Layout::Shape_CylinderSurface &cylinder)
{
    osg::Vec3f eye = cylinder.firstBaseCenter();
    osg::Vec3f center = cylinder.secondBaseCenter();

    osg::Cylinder *osgCylinder = new osg::Cylinder;
    osgCylinder->setRadius(getScaledDistance(100));
    osgCylinder->setCenter(getScaledPosition(center));

    osg::ShapeDrawable *sd = new osg::ShapeDrawable;
    sd->setShape(osgCylinder);
    sd->setColor(osg::Vec4 (0, 0, 1.0, /*0.06*/0.0));

    //transparency of cylinder
    sd->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
    sd->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    sd->getStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
    sd->getStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    sd->getStateSet()->setAttributeAndModes(new osg::BlendFunc, osg::StateAttribute::ON);
    sd->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    sd->getStateSet()->setRenderBinDetails(11, "RenderBin");
    //

    osg::Geode *geode = new osg::Geode;
    geode->addDrawable(sd);

    createdVisualizer_ = geode;
}
示例#2
0
/**
 * Draw the arrow triangle.
 *
 * @param[in] painter Painter that must be used.
 * @param[in] plot Plot where arrow must be plotted.
 */
void Arrow2D::drawArrow(QPainter &painter, Plot2D *plot){
	painter.setPen(m_arrowLinePen);
	painter.setBrush(m_arrowBrush);
	const auto initialPoint = getScaledPosition(m_pivot, plot);
	const auto finalPoint = getScaledPosition(m_finalPoint, plot);
	const double angle = atan2(finalPoint.y() - initialPoint.y(), finalPoint.x() - initialPoint.x());
	const double arrowLength = getScaledDimensionX(m_arrowLength, plot);
	const double arrowWidth = getScaledDimensionX(m_arrowWidth, plot);
	const QPointF p1(-m_arrowLength + finalPoint.x(), -m_arrowWidth * 0.5 + finalPoint.y());
	const QPointF p2(-m_arrowLength + finalPoint.x(), m_arrowWidth * 0.5 + finalPoint.y());
	QPolygonF arrow;
	arrow << finalPoint << p1 << p2;
	QTransform transform;
	transform.rotateRadians(angle);
	const QPolygonF rotatedArrow = transform.map(arrow);
	const auto deltaPosition = arrow.front() -  rotatedArrow.front();
	QTransform translateTransform;
	translateTransform.translate(deltaPosition.x(), deltaPosition.y());
	const QPolygonF rotoTranslatedArros = translateTransform.map(rotatedArrow);
	painter.drawPolygon(rotoTranslatedArros);
}
void ShapeVisitor_VisualizerCreator::visit( Layout::Shape_Intersection& shape )
{

	osg::Vec3 center;
	//osg::Vec3 normalVector;

	if ( shape.getCompositeType() == Layout::Shape_Composite::CompositeType::CIRCLE ) {
		float radius = 0;

		Layout::Shape_Composite::ShapesListType& shapes = shape.getShapes();
		Layout::Shape_Composite::ShapesListType::iterator it = shapes.begin();

		if ( QSharedPointer<Layout::Shape_Sphere> sphere = qSharedPointerCast<Layout::Shape_Sphere>( *it ) ) {
			radius = sphere->getRadius();
			center = sphere->getCenter();
		}
		else {
			// TODO: What if the first condition does not apply
		}
		++it;

		//if(QSharedPointer<Layout::Shape_Plane> plane = qSharedPointerCast<Layout::Shape_Plane>(*it)){
		//   normalVector = plane->getNormalVector();
		//}

		osg::Cylinder* cylinder = new osg::Cylinder;
		cylinder->setCenter( getScaledPosition( center ) );
		cylinder->setRadius( getScaledDistance( radius ) );
		cylinder->setHeight( 1 );

		osg::ShapeDrawable* sd = new osg::ShapeDrawable;
		sd->setShape( cylinder );

		//volovar zmena apha nie je konstanta 0.06f
		sd->setColor( osg::Vec4( 0.0f, 0.f, 1.0f, shape.getAlpha() ) );

		sd->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
		sd->getStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
		sd->getStateSet()->setMode( GL_DEPTH_TEST,osg::StateAttribute::OFF );
		sd->getStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
		sd->getStateSet()->setAttributeAndModes( new osg::BlendFunc, osg::StateAttribute::ON );
		sd->getStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
		sd->getStateSet()->setRenderBinDetails( 11, "RenderBin" );

		osg::Geode* geode = new osg::Geode;
		geode->addDrawable( sd );

		createdVisualizer_ = geode;

	}

}
void ShapeVisitor_VisualizerCreator::visualizeSphere( Layout::Shape_AbstractSphere& abstractSphere )
{
	osg::Sphere* sphere = new osg::Sphere;
	sphere->setRadius( getScaledDistance( abstractSphere.getRadius() ) );
	sphere->setCenter( getScaledPosition( abstractSphere.getCenter() ) );

	osg::ShapeDrawable* sd = new osg::ShapeDrawable;
	sd->setShape( sphere );
	//volovar zmena
	osg::PolygonMode* polygonMode = new osg::PolygonMode;  //podla http://snipplr.com/view/30978/osg-wireframe-display/

	sd->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
	switch ( abstractSphere.getRenderType() ) { //prepinanie medzi vykreslovacimi modmi shapu
		case Layout::Shape_AbstractSphere::SOLID:

			sd->setColor( osg::Vec4( 0.f, 0.f, 1.0f, abstractSphere.getAlpha() ) );
			sd->getStateSet()->setAttributeAndModes( new osg::BlendFunc, osg::StateAttribute::ON );
			sd->getStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
			break;
		case Layout::Shape_AbstractSphere::WIREFRAME:
			polygonMode->setMode( osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE );
			sd->setColor( osg::Vec4( 0.f, 0.f, 1.0f, abstractSphere.getAlpha() ) );
			sd->getStateSet()->setAttributeAndModes( polygonMode,
					osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON );
			sd->getStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
			break;
		case Layout::Shape_AbstractSphere::CIRCLE:
			break;
		default:
			return;
	}
	//volovar koniec zmeny


	//transparency of sphere

	sd->getStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
	sd->getStateSet()->setMode( GL_DEPTH_TEST,osg::StateAttribute::OFF );
	sd->getStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );

	sd->getStateSet()->setRenderBinDetails( 11, "RenderBin" );
	//

	osg::Geode* geode = new osg::Geode;
	geode->addDrawable( sd );

	createdVisualizer_ = geode;
}
void ShapeVisitor_VisualizerCreator::visualizeSphere (Layout::Shape_AbstractSphere & abstractSphere) {
	osg::Sphere * sphere = new osg::Sphere;
	sphere->setRadius (getScaledDistance (abstractSphere.getRadius ()));
	sphere->setCenter (getScaledPosition (abstractSphere.getCenter ()));

	osg::ShapeDrawable * sd = new osg::ShapeDrawable;
	sd->setShape (sphere);
	sd->setColor (osg::Vec4 (0, 0, 1.0, 0.06));

	//transparency of sphere
	sd->getOrCreateStateSet()->setMode (GL_BLEND, osg::StateAttribute::ON);
	sd->getStateSet()->setRenderingHint (osg::StateSet::TRANSPARENT_BIN);
	sd->getStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
	sd->getStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
	sd->getStateSet()->setAttributeAndModes(new osg::BlendFunc, osg::StateAttribute::ON);
	sd->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
	sd->getStateSet()->setRenderBinDetails( 11, "RenderBin");
	//

	osg::Geode * geode = new osg::Geode;
	geode->addDrawable (sd);

    createdVisualizer_ = geode;
}
void ShapeVisitor_VisualizerCreator::visit (Layout::Shape_Plane & shape) {
	// OSG does not support InfinitePlane drawing at this time, maybe try to use this piece of code with the new version of OSG
	/*
	osg::InfinitePlane * plane = new osg::InfinitePlane;
	plane->set (shape.getNormalVector (), getScaledDistance (shape.getD ()));

	osg::ShapeDrawable * sd = new osg::ShapeDrawable;
	sd->setShape (plane);
	sd->setColor (osg::Vec4 (0, 0.5, 0.0, 0.5));
	*/

	// now we use a temporary code instead - drawing a plane using box:

	// center
	osg::Vec3 center (0, 0, (- shape.getD ()) / shape.getNormalVector ().z () ); // some point on the plane

	// rotation
	osg::Quat quat;
	quat.makeRotate (osg::Z_AXIS, shape.getNormalVector ());

	osg::Box * box = new osg::Box;
	box->setCenter (getScaledPosition (center));
	box->setRotation (quat);
	box->setHalfLengths (osg::Vec3 (1000, 1000, 1));

	osg::ShapeDrawable * sd = new osg::ShapeDrawable;
	sd->setShape (box);
	sd->setColor (osg::Vec4 (0, 0, 1.0, 0.06));
	sd->getOrCreateStateSet()->setMode (GL_BLEND, osg::StateAttribute::ON);
	sd->getStateSet()->setRenderingHint (osg::StateSet::TRANSPARENT_BIN);

	osg::Geode * geode = new osg::Geode;
	geode->addDrawable (sd);

	createdVisualizer_ = geode;
}
示例#7
0
/**
 * Draw the arrow line.
 *
 * @param[in] painter Painter that must be used.
 * @param[in] plot Plot where arrow must be plotted.
 */
void Arrow2D::drawLine(QPainter &painter, Plot2D *plot) {
	const auto initialPoint = getScaledPosition(m_pivot, plot);
	const auto finalPoint = getScaledPosition(m_finalPoint, plot);
	painter.setPen(m_linePen);
	painter.drawLine(initialPoint, finalPoint);
}