Example #1
0
void QGLView::setupVBOs()
{
    setupCube();
    setupCylinder(1.0, QVector3D(0,0,0),
                  1.0, QVector3D(0,0,1),
                  16, Cylinder);
    setupCylinder(1.0, QVector3D(0,0,0),
                  0.0, QVector3D(0,0,1),
                  16, Cone);
    setupSphere(16);
    setupLineVertexBuffer();
    setupTextVertexBuffer();
}
Example #2
0
osg::MatrixTransform* setupAnimtkNode()
{
    osg::Vec3 v[5];
    v[0] = osg::Vec3(0,0,0);
    v[1] = osg::Vec3(10,-50,0);
    v[2] = osg::Vec3(30,-10,20);
    v[3] = osg::Vec3(-10,20,-20);
    v[4] = osg::Vec3(0,0,0);
    osg::MatrixTransform* node = new osg::MatrixTransform;
    AnimtkUpdateCallback* callback = new AnimtkUpdateCallback;
    osgAnimation::Vec3CubicBezierKeyframeContainer* keys = callback->_sampler->getOrCreateKeyframeContainer();
    keys->push_back(osgAnimation::Vec3CubicBezierKeyframe(0, osgAnimation::Vec3CubicBezier(
                                                        v[0], // pos
                                                        v[0] + (v[0] - v[3]), // p1 
                                                        v[1] - (v[1] - v[0]) // p2
                                                        )));
    keys->push_back(osgAnimation::Vec3CubicBezierKeyframe(2, osgAnimation::Vec3CubicBezier(
                                                        v[1], // pos
                                                        v[1] + (v[1] - v[0]),
                                                        v[2] - (v[2] - v[1])
                                                        )));
    keys->push_back(osgAnimation::Vec3CubicBezierKeyframe(4, osgAnimation::Vec3CubicBezier(
                                                        v[2], // pos
                                                        v[2] + (v[2] - v[1]),
                                                        v[3] - (v[3] - v[2])
                                                        )));
    keys->push_back(osgAnimation::Vec3CubicBezierKeyframe(6, osgAnimation::Vec3CubicBezier(
                                                        v[3], // pos
                                                        v[3] + (v[3] - v[2]),
                                                        v[4] - (v[4] - v[3])
                                                        )));
    keys->push_back(osgAnimation::Vec3CubicBezierKeyframe(8, osgAnimation::Vec3CubicBezier(
                                                        v[4], // pos
                                                        v[4] + (v[4] - v[3]),
                                                        v[0] - (v[0] - v[4])
                                                        )));

    callback->start();
    node->setUpdateCallback(callback);
    node->addChild(setupCube());
    return node;
}
Example #3
0
// called once by Qt GUI system, to allow initialization for OpenGL requirements
void Renderer::initializeGL()
{
    // Qt support for inline GL function calls
	initializeOpenGLFunctions();

    // sets the background clour
    glClearColor(0.7f, 0.7f, 0.7f, 1.0f);

    // links to and compiles the shaders, used for drawing simple objects
    m_program = new QOpenGLShaderProgram(this);
    m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/Shaders/Phong/per-fragment-phong.vs.glsl");
    m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/Shaders/Phong/per-fragment-phong.fs.glsl");
    m_program->link();
    m_posAttr = m_program->attributeLocation("position_attr");
    m_colAttr = m_program->attributeLocation("colour_attr");
    m_norAttr = m_program->attributeLocation("normal_attr");
    m_PMatrixUniform = m_program->uniformLocation("proj_matrix");
    m_VMatrixUniform = m_program->uniformLocation("view_matrix");
    m_MMatrixUniform = m_program->uniformLocation("model_matrix");
    m_programID = m_program->programId();

    setupCube();
}
Example #4
0
void iARenderer::initialize( vtkImageData* ds, vtkPolyData* pd, int e )
{
	imageData = ds;
	polyData = pd;
	cellLocator->SetDataSet(polyData);
	if(polyData)
		if( polyData->GetNumberOfCells() )
			cellLocator->BuildLocator();
	ext = e;
	double spacing[3];	ds->GetSpacing(spacing);
	ren->SetLayer(0);
	ren->UseDepthPeelingOn();
#if (VTK_MAJOR_VERSION >= 8 && defined(VTK_OPENGL2_BACKEND) && QT_VERSION >= 0x050400 )
	ren->UseDepthPeelingForVolumesOn();
#endif
	labelRen->SetLayer(1);
	labelRen->InteractiveOff();
	labelRen->UseDepthPeelingOn();
	renWin->SetNumberOfLayers(5);
	renWin->AddRenderer(ren);
	renWin->AddRenderer(labelRen);
	interactor = renWin->GetInteractor();
	setPointPicker();	
	InitObserver();

	QImage img;
	img.load(":/images/fhlogo.png");
	logoImage->SetQImage(&img);
	logoImage->Update();
	logoRep->SetImage(logoImage->GetOutput( ));
	logoWidget->SetInteractor(interactor);
	logoWidget->SetRepresentation(logoRep);
	logoWidget->SetResizable(false);
	logoWidget->SetSelectable(true);
	logoWidget->On();

	interactor->Initialize();

	// setup cube source
	cSource->SetXLength(ext * spacing[0]);
	cSource->SetYLength(ext * spacing[1]);
	cSource->SetZLength(ext * spacing[2]);
	cMapper->SetInputConnection(cSource->GetOutputPort());
	cActor->SetMapper(cMapper);
	cActor->GetProperty()->SetColor(1,0,0);

	setupCutter();
	setupCube();
	setupAxes(spacing);
	setupOrientationMarker();
	setupRenderer();

	labelRen->SetActiveCamera(cam);
	ren->SetActiveCamera(cam);
	setCamPosition( 0,0,1, 1,1,1 ); // +Z

	m_profileLineMapper->SetInputConnection(m_profileLineSource->GetOutputPort());
	m_profileLineActor->SetMapper(m_profileLineMapper);
	m_profileLineStartPointMapper->SetInputConnection(m_profileLineStartPointSource->GetOutputPort());
	m_profileLineStartPointActor->SetMapper(m_profileLineStartPointMapper);
	m_profileLineEndPointMapper->SetInputConnection(m_profileLineEndPointSource->GetOutputPort());
	m_profileLineEndPointActor->SetMapper(m_profileLineEndPointMapper);
	m_profileLineActor->GetProperty()->SetColor(0.59, 0.73, 0.94);//ffa800//150, 186, 240
	m_profileLineActor->GetProperty()->SetLineWidth(2.0);
	m_profileLineActor->GetProperty()->SetLineStipplePattern(0x00ff);//0xf0f0
	m_profileLineActor->GetProperty()->SetLineStippleRepeatFactor(1);
	m_profileLineActor->GetProperty()->SetPointSize(2);
	m_profileLineStartPointSource->SetRadius(2 * spacing[0]);
	m_profileLineEndPointSource->SetRadius(2 * spacing[0]);
	m_profileLineStartPointActor->GetProperty()->SetColor(1.0, 0.65, 0.0);
	m_profileLineEndPointActor->GetProperty()->SetColor(0.0, 0.65, 1.0);


	 //slicing cube settings for surface extraction
	 m_sliceCubeMapper->SetInputConnection(m_slicingCube->GetOutputPort());
	 m_sliceCubeActor->SetMapper(m_sliceCubeMapper);
	 m_sliceCubeActor->GetProperty()->SetColor(1.0, 0, 0);
	 m_sliceCubeActor->GetProperty()->SetRepresentationToWireframe();
	 m_sliceCubeActor->GetProperty()->SetOpacity(1); 
	 m_sliceCubeActor->GetProperty()->SetLineWidth(2.3); 	 
	 m_sliceCubeActor->GetProperty()->SetAmbient(1.0);
	 m_sliceCubeActor->GetProperty()->SetDiffuse(0.0);
	 m_sliceCubeActor->GetProperty()->SetSpecular(0.0);
	 
	 m_sliceCubeActor->SetVisibility(false);

	 this->	setArbitraryProfileOn(false);

	double center[3], origin[3];
	const int * dim = imageData->GetDimensions();
	if (dim[0] == 0 || dim[1] == 0 || dim[2] == 0)
		return;
	const double * spc = imageData->GetSpacing();
	for (int i = 0; i < 3; ++i)
	{
		center[i] = dim[i] * spc[i] / 2;
		origin[i] = 0;
	}
	for (int s = 0; s < 3; ++s)
	{
		m_slicePlaneSource[s]->SetOrigin(origin);
		double point1[3], point2[3];
		for (int j = 0; j < 3; ++j)
		{
			point1[j] = 0;
			point2[j] = 0;
		}
		point1[GetSliceAxis(s, 0)] += 1.1 * dim[GetSliceAxis(s, 0)] * spc[GetSliceAxis(s, 0)];
		point2[GetSliceAxis(s, 1)] += 1.1 * dim[GetSliceAxis(s, 1)] * spc[GetSliceAxis(s, 1)];
		m_slicePlaneSource[s]->SetPoint1(point1);
		m_slicePlaneSource[s]->SetPoint2(point2);
		m_slicePlaneSource[s]->SetCenter(center);
		m_slicePlaneMapper[s]->SetInputConnection(m_slicePlaneSource[s]->GetOutputPort());
		m_slicePlaneActor[s]->SetMapper(m_slicePlaneMapper[s]);
		m_slicePlaneActor[s]->GetProperty()->SetColor( (s == 0) ? 1:0, (s == 1) ? 1 : 0, (s == 2) ? 1 : 0);
		m_slicePlaneActor[s]->GetProperty()->SetOpacity(1.0);
		m_slicePlaneActor[s]->SetVisibility(false);
		m_slicePlaneMapper[s]->Update();
	}
}