Example #1
0
	void SetLightStatus( bool in_shadow = false )
	{
		SetLightPos();
		SetLightfv( in_shadow );
	}
Example #2
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);
}
BOOL CKWResearchWorkDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
	CKWResearchWorkView* pView=(CKWResearchWorkView*)GetView(RUNTIME_CLASS(CKWResearchWorkView));
	if (pMain==NULL)
	{
		pView->Reset(true);
	}
	else
	{
		pView->Reset(false);
		CMenu* pMenu=pMain->GetMenu();
		pMenu->CheckMenuItem(ID_VIEW_3DAXISON,MF_UNCHECKED);	
		this->bAxis=false;
		this->bShowPrimalMesh=true;
		pMenu->CheckMenuItem(ID_VIEW_PRIMALMESH,MF_CHECKED);	
//		this->iViewStyle=1;
	}

	Mesh.clear();
	this->MeshEditing.Init(this);
	this->MeshDeformation.Init(this);
	this->MeshExtrusion.Init(this);
	this->MeshCutting.Init(this);
	this->MeshSmoothing.Init(this);
	this->MeshCreation.Init(this);
	this->Test.Init(this);
//	this->iEditMode=CREATION_MODE;
	OnModeCreation();


	float pos[4] = { 0, 0, 1, 0};
	SetLightPos(pos);

	this->iManipMode=VIEW_SELECTION_MODE;
	this->iRBSelName=NONE_SELECTED;
	this->iLBSelName=NONE_SELECTED;
	this->iColorMode=COLOR_ORIGINAL;
	vecDefaultColor.clear();
	vecDefaultColor.push_back(0.5);
	vecDefaultColor.push_back(0.9);
	vecDefaultColor.push_back(0.4);
	vecDefaultColor.push_back(1.0);
	this->iViewStyle=SMOOTH_VIEW;
	this->bAxis=false;
	this->iRenderPreMesh=MESH_PREVIEW;
	//init control panel(general tab)
	CControlPanel* pCP=(CControlPanel*)(this->GetView(RUNTIME_CLASS(CControlPanel)));
	if (pCP->GetCPGeneral()!=NULL)
	{
		pCP->GetCPGeneral()->Init();
	}

	UpdateAllViews(NULL);

	return TRUE;
}