Exemple #1
0
VOID Render()
{
	SetupLight() ;
	SetupLight() ;
	SetupMatrix() ;

	g_pCamera->Update(0.1f, 1.0f) ;

	// Clear the back-buffer to a RED color
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// Draw teapot
		g_pTeapotMesh->DrawSubset(0) ;

		RenderFog(0xff00ff00, D3DFOG_LINEAR, TRUE, 10.f) ;

		//RenderGround() ;

		// End the scene
		g_pd3dDevice->EndScene();
	}

	// Present the back-buffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Exemple #2
0
VOID Render(float timeDelta)
{
	if (!g_bActive)
		Sleep(50) ;

	SetupMatrix(timeDelta);
	SetupLight();

	// Clear the back-buffer to a BLUE color
	float color[4] = { 0.0f, 0.125f, 0.3f, 1.0f };
	g_pd3dDevice->ClearRenderTargetView(g_pRenderTargetView, color);

	// Set the input layout
	g_pd3dDevice->IASetInputLayout(g_pVertexLayout);

	// Set rasterazition state
	g_pd3dDevice->RSSetState(g_pRasterizerState);

	// Apply each pass in technique and draw triangle.
	D3D10_TECHNIQUE_DESC techDesc;
	g_pTechnique->GetDesc(&techDesc);
	for (unsigned int i = 0; i < techDesc.Passes; ++i)
	{
		g_pTechnique->GetPassByIndex(i)->Apply(0);
	}

	// Draw sphere
	g_pSphere->DrawSubset(0);

	// Present the sence from back buffer to front buffer
	g_pSwapChain->Present(0, 0);
}
void Mesh::setupVBOs() {
  // delete all the old geometry
  mesh_tri_verts.clear(); 
  light_vert.clear();
  cleanupVBOs();
  // setup the new geometry
  Vec3f light_position = LightPosition();
  SetupLight(light_position);
  SetupMesh();
  SetupPlateVisualization();
  bbox.setupVBOs();
}
/* main OpenGL initialization routine */
static void
initializeGL(ModeInfo *mi, GLsizei width, GLsizei height) 
{
  int style;
  int mode;

  reshape_extrusion(mi, width, height);
  glViewport( 0, 0, width, height ); 

  glEnable(GL_DEPTH_TEST);
  glDisable (GL_CULL_FACE);
  glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, True);
  glShadeModel(GL_SMOOTH);

# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
  MI_IS_WIREFRAME(mi) = 0;
# endif

  if (do_light)
	SetupLight();
  if (MI_IS_WIREFRAME(mi)) {
	glPolygonMode(GL_FRONT,GL_LINE);
  	glPolygonMode(GL_BACK,GL_LINE);
  }
  if (do_texture) {
	Create_Texture(mi, which_image);
	glEnable(GL_TEXTURE_2D);

	/* configure the pipeline */
	style = TUBE_JN_CAP;
	style |= TUBE_CONTOUR_CLOSED;
	style |= TUBE_NORM_FACET;
	style |= TUBE_JN_ANGLE;
	gleSetJoinStyle (style);

	if (do_texture) {
	  mode = GLE_TEXTURE_ENABLE | GLE_TEXTURE_VERTEX_MODEL_FLAT;
	  glMatrixMode (GL_TEXTURE); glLoadIdentity ();
	  glScalef (0.25, 0.1, 1); glMatrixMode (GL_MODELVIEW);
	  gleTextureMode (mode);
	}
  }

}
Exemple #5
0
VOID Render()
{
	// Set a red light
	SetupLight(D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)) ;

	SetupMatrix() ;

	// Clear the back-buffer to a RED color
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(55,205,0), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		g_pTeapotMesh->DrawSubset(0) ;

		/*
		Here, we create a small new viewport and place it at the bottom right of the main window
		the new view port start at position(400, 400) with size(200, 200)
		*/
		D3DVIEWPORT9 viewport ;
		viewport.X = 400 ;
		viewport.Y = 400 ;
		viewport.Width = 200 ;
		viewport.Height = 200 ;
		viewport.MinZ = 0.0f ;
		viewport.MaxZ = 1.0f ;
		
		// Set the new view port
		g_pd3dDevice->SetViewport(&viewport) ;

		// Clear the view port to yellow
		// This will failed in Debug libaries
		g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,0), 1.0f, 0 );

		// Draw the teapot again
		g_pTeapotMesh->DrawSubset(0) ;

		// End the scene
		g_pd3dDevice->EndScene();
	}

	// Present the back-buffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
static gboolean
expose_event_preview3d(GtkWidget * widget, GdkEventExpose * UNUSED(eventDetails), Material * pMat)
{
    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

    if (!gdk_gl_drawable_gl_begin(gldrawable, gtk_widget_get_gl_context(widget)))
        return TRUE;

    CheckOpenglError();

    SetupLight();
    Draw(pMat);

    gdk_gl_drawable_swap_buffers(gldrawable);

    gdk_gl_drawable_gl_end(gldrawable);

    return TRUE;
}
Exemple #7
0
//! [7]
void GLWidget::paintGL()
{
    if (m_pMain == NULL)
        return;

    if (m_pMain->m_pRTstudy == NULL) //if DICOM RT SS is not ready
        return;
    
    glMatrixMode(GL_MODELVIEW);									// Select The Modelview Matrix
    glLoadIdentity();											// Reset The Modelview Matrix
    //SetupLight();			// Setup Light

    SetLightPos(500, 500, 0);
    SetupLight();

    SetCamera();
    glEnable(GL_COLOR_MATERIAL);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //glLoadIdentity();
    //glTranslatef(0.0, 0.0, -10.0); //should be fixed here
    //glTranslatef(0.0, 0.0, -100.0); //should be fixed here
    /*glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
    glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
    glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);*/
    
    //glScalef(0.1, 0.1, 0.1);
    //update zoom
    //glScalef(m_curZoom, m_curZoom, m_curZoom);

//    logo->draw();

    //Draw func here  
    //glEnableClientState(GL_VERTEX_ARRAY);
    //glEnableClientState(GL_NORMAL_ARRAY);

    /*for (int i = 0; i < parts.count(); ++i)
    parts[i]->draw();*/


    //qMultMatrix(mat);

    //original one
    //glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices + start)

    Rtss::Pointer rtss = m_pMain->m_pRTstudy->get_rtss();
    int numOfStruct = rtss->num_structures;

    if (m_pMain->m_vStructProperty.size() != numOfStruct)
    {
        cout << "Fatal error! number of structures is not matching" << endl;
        return;
    }
    
    //This is read only. So mutex would not be neccessary
    VEC3D motionDelta = m_pMain->m_motionDelta;

    /*cout << motionDelta.fX << " " <<
        motionDelta.fY << " " <<
        motionDelta.fZ << endl;*/
    
    STRUCT_PROPT curProperty;

    for (int i = 0; i < numOfStruct; i++)
    {
        curProperty = m_pMain->m_vStructProperty.at(i);

        //bool bSparse = false;
        bool bIncludeMotion = false;
        int zStep = 1;

        if (!curProperty.bVisible3D)
            continue;

        Rtss_roi* curRoi = rtss->slist[i];
        //QString ROI_name = curRoi->name.c_str();

        QString ROI_name = curProperty.structName;
        
        //if (ROI_name.contains("Skin"))
        //{
        //    bSparse = true;
        //    zStep = 10;//10 mm
        //}

        zStep = curProperty.iSparsity3D;
        bIncludeMotion = curProperty.bMotionEnable3D;        

        //if (ROI_name.contains("Tumor_1"))
        /* if (ROI_name == strROIName)
         {*/
        //cout << "ROI is found: " << ROI_name.toLocal8Bit().constData() << endl;

        int numContours = curRoi->num_contours;
        //color: 
        //QString strColor =
            //GetColor
         VEC3D fColor;
        //fColor = m_pMain->GetRGBFomDCMStr(curRoi->get_dcm_color_string().c_str());

         fColor = curProperty.fColor;

         //curProperty.Thick is not used now

        glLineWidth(1.0);
        glColor3f(fColor.fX, fColor.fY, fColor.fZ);

        int inAxialStep = qRound(curProperty.iSparsity3D/2.0);
        if (inAxialStep < 1)
            inAxialStep = 1;

        glPushMatrix();

        for (int j = 0; j < numContours; j += zStep)
        {
            Rtss_contour* curContour = curRoi->pslist[j]; //single contour: contains points with same z value            
           
            if (curContour->num_vertices < 2)
                continue;

            //glPushMatrix();
            
            VEC3D curTransformedPt;
            VEC3D nextTransformedPt;
            VEC3D curPosDCM;
            VEC3D nextPosDCM;

            glBegin(GL_LINES);
            

            for (int k = 0; k < curContour->num_vertices; k = k + inAxialStep)
            {
                //if (k == curContour->num_vertices - 1)

                if (k > curContour->num_vertices - 1 -inAxialStep )                    
                {
                    curPosDCM.fX = curContour->x[k];
                    curPosDCM.fY = curContour->y[k];
                    curPosDCM.fZ = curContour->z[k];

                    nextPosDCM.fX = curContour->x[0];
                    nextPosDCM.fY = curContour->y[0];
                    nextPosDCM.fZ = curContour->z[0];                    
                }
                else
                {
                    curPosDCM.fX = curContour->x[k];
                    curPosDCM.fY = curContour->y[k];
                    curPosDCM.fZ = curContour->z[k];

                    /*nextPosDCM.fX = curContour->x[k + 1];
                    nextPosDCM.fY = curContour->y[k + 1];
                    nextPosDCM.fZ = curContour->z[k + 1];*/

                    nextPosDCM.fX = curContour->x[k + inAxialStep];
                    nextPosDCM.fY = curContour->y[k + inAxialStep];
                    nextPosDCM.fZ = curContour->z[k + inAxialStep];
                    //vOutputPt3D.push_back(tmpPt);

                    //GetTransformedDCM3D(): plan ISo, couch rot, couch shift
                    //transformedPt = GetTransformedDCM3DFromRawDCM(curPosDCM, planIsoDCM, couchTrans, couchRotDeg);                   
                }

                //curTransformedPt = m_pMain->GetTransformedDCM3DFromRawDCM(curPosDCM, bIncludeMotion);
                //nextTransformedPt = m_pMain->GetTransformedDCM3DFromRawDCM(nextPosDCM, bIncludeMotion);

                    VEC3D planIsoDCM; VEC3D couchTrans; VEC3D couchRotDeg;
                
                //YKTEMP
                /*    planIsoDCM.fX = m_pMain->ui.lineEditPlanIsoDCM_X->text().toDouble();
                    planIsoDCM.fY = m_pMain->ui.lineEditPlanIsoDCM_Y->text().toDouble();
                    planIsoDCM.fZ = m_pMain->ui.lineEditPlanIsoDCM_Z->text().toDouble();
                */

                    planIsoDCM = m_pMain->m_TempPlanIso;//Saved when contour is calculated

                    couchTrans.fX = m_pMain->ui.lineEditCouchLat->text().toDouble();
                    couchTrans.fY = m_pMain->ui.lineEditCouchVert->text().toDouble();
                    couchTrans.fZ = m_pMain->ui.lineEditCouchSI->text().toDouble();
                    //For future use
                    couchRotDeg.fX = m_pMain->ui.lineEditCouchPitch->text().toDouble();
                    couchRotDeg.fY = m_pMain->ui.lineEditCouchYaw->text().toDouble();
                    couchRotDeg.fZ = m_pMain->ui.lineEditCouchRoll->text().toDouble();
                //
                //    return GetTransformedDCM3DFromRawDCM(curPosDCM, planIsoDCM, couchTrans, couchRotDeg);


                    curTransformedPt = YKPROC::GetTransformedDCM3DFromRawDCM(curPosDCM, planIsoDCM, couchTrans, couchRotDeg);
                    nextTransformedPt = YKPROC::GetTransformedDCM3DFromRawDCM(nextPosDCM, planIsoDCM, couchTrans, couchRotDeg);

                if (bIncludeMotion)
                {
                    curTransformedPt.fX = curTransformedPt.fX + motionDelta.fX;
                    curTransformedPt.fY = curTransformedPt.fY + motionDelta.fY;
                    curTransformedPt.fZ = curTransformedPt.fZ + motionDelta.fZ;

                    nextTransformedPt.fX = nextTransformedPt.fX + motionDelta.fX;
                    nextTransformedPt.fY = nextTransformedPt.fY + motionDelta.fY;
                    nextTransformedPt.fZ = nextTransformedPt.fZ + motionDelta.fZ;
                }

                glVertex3f(curTransformedPt.fX, curTransformedPt.fY, curTransformedPt.fZ);
                glVertex3f(nextTransformedPt.fX, nextTransformedPt.fY, nextTransformedPt.fZ);
            }

            glEnd();
          
        }
        //}
        glPopMatrix();
    }

    //Draw Tracked marker pos

    int curIdx = m_pMain->m_iLastProcessedIdx;

    if (curIdx < 0)
        return;


    vector<VEC3D>::iterator it;


    float radiusPoint = 5.0;
    int slices = 30;
    int stacks = 30;

    int cnt = 0;
    for (it = m_pMain->m_arrYKImage[curIdx].m_vEstiMarker3D.begin();
        it != m_pMain->m_arrYKImage[curIdx].m_vEstiMarker3D.end(); ++it)
    {
        VEC3D tmpPos = (*it);
        //Draw

        if (cnt ==0)
            glColor3ub(255, 0, 0);
        else if (cnt == 1)
            glColor3ub(0, 255, 0);
        else if (cnt == 2)
            glColor3ub(0, 0, 255);
        
        glPushMatrix();
        //tmpPos: tracked result-->tx coordinate
        //fY --> SI --> Dicom Z
        //fZ --> AP --> DICOM -Y

        glTranslated(tmpPos.fX, -tmpPos.fZ, tmpPos.fY);
        gluSphere(m_quadratic, radiusPoint, slices, stacks);
        glPopMatrix();

        cnt++;
    }
       

   // glDisableClientState(GL_VERTEX_ARRAY);
    //glDisableClientState(GL_NORMAL_ARRAY);
}
  EarthViewer(const Vec2<int>& size, const float scale, const bool oblong, Touch& touch, Keyinp& keyinp, const std::string& path, const std::string& lang) :
    touch_(touch),
    keyinp_(keyinp),
    size_(size.x / scale, size.y / scale),
    params_(path + "devdata/params.json"),
    scale_(scale),
    aspect_((float)size.x / (float)size.y),
    camera_(Camera::PERSPECTIVE),
    cockpit_(Camera::ORTHOGONAL),
    localize_(lang, path),
    earth_(params_.value().get<picojson::object>()["earth"].get<picojson::object>(), path, camera_),
    rotate_mix_(),
    place_index_()
  {
    DOUT << "EarthViewer()" << std::endl;

    picojson::object& params = params_.value().get<picojson::object>();

    camera_.oblong(oblong);
    SetupCamera(camera_, params["camera"].get<picojson::object>(), aspect_);
    cockpit_.setSize(size.x / scale, size.y / scale);

    {
      picojson::array& array = params["lights"].get<picojson::array>();
      for (picojson::array::iterator it = array.begin(); it != array.end(); ++it)
      {
        Light light;
        SetupLight(light, it->get<picojson::object>());
        lights_.push_back(light);
      }
      earth_.light(lights_);
    }

    env_.touch       = &touch_;
    env_.keyinp      = &keyinp_;
    env_.path        = &path;
    env_.savePath    = &path;
    env_.size        = &size_;
    env_.scale       = scale_;
    env_.params      = &params_;
    env_.task        = &task_;
    env_.camera      = &camera_;
    env_.cockpit     = &cockpit_;
    env_.earth       = &earth_;
    env_.earthLight  = &lights_[0];
    env_.fonts       = &fonts_;
    env_.texMng      = &texMng_;
    env_.localize    = &localize_;

    env_.earth_texture = 0;
    earth_.texture(env_.earth_texture);
    earth_.setRotSpeed(0);

    {
      const std::string& file = params["game"].get<picojson::object>()["places"].get<std::string>();
      Json places = Json(path + file);
      places_ = places.value().get<picojson::object>();
      for (picojson::object::iterator it = places_.begin(); it != places_.end(); ++it)
      {
        place_names_.push_back(&it->first);
      }
    }

    task_.add<Control>(TASK_PRIO_SYS, env_);
    task_.add<Game2DSetup>(TASK_PRIO_2D_TOPPRIO, env_);
    task_.add<GameWorld>(TASK_PRIO_3D_TOPPRIO, env_);
    env_.task->add<PlaceDisp>(TASK_PRIO_2D, env_);
    // task_.add<Equator>(TASK_PRIO_3D, env_);
    task_.add<TouchEft>(TASK_PRIO_3D, env_);
  }
void DrawCube()
{
	// Setup a point light
	SetupLight();
	g_pMesh->DrawSubset(0);
}