[vtkusers] Need you help

chen hongwei szjoin at gmail.com
Mon Mar 21 03:22:53 EST 2005


Dear friend:

       Nice to meet  you  . i  am  join  ,I have some problem to need
your help .

       Now  I have some point that is closed loop(like  circle)  example:

       

           This points Used CPoint descrip in visual c++6.0

      I  Must  Create 3d sourface  with  this  point , like this :

   

     But  I  don't  Know  how  to do it . I have some  code  but  the 
result is't  idealization

     Can you give me some good  idea and  advice  or  Some  example  code ,

thank your help

    

     My  Code :

   bool  C3DControl::CreateContouring3D(CArray<CIRCLE,CIRCLE>*
pACreate3DData,map<int,int> &mContourInfo,CSize sizeWindow)

{

       if(this->m_bCreated)  return RETURN_FAILURE;

       VERDICT_POINTER_IS_NULL(pACreate3DData);

       this->Delete3D();

       this->pActor =vtkActor::New();

       try{

              this->m_bCreated=true;

              this->pRenderer= vtkRenderer::New();

              if(this->pRenderer==NULL){

                     throw("this->pRenderer::New()
Failure....................");

              }

              this->pRenderWindow= vtkWin32OpenGLRenderWindow::New();

              if(this->pRenderWindow==NULL){

                     throw("this->pRenderWindow::New()
Failure....................");

              }

              this->pRenderWindow->AddRenderer(this->pRenderer);

              if(this->m_hwnd!=NULL){

                     this->pRenderWindow->SetParentId(this->m_hwnd);

              }

              else{

                    
throw("this->m_hwnd=NULL.....................................");

              }

              this->pWindowInteractor= vtkWin32RenderWindowInteractor::New();

              if(this->pWindowInteractor==NULL){

                     throw("this->pWindowInteractor::New()
Failure....................");

              }

              this->pWindowInteractor->SetRenderWindow(this->pRenderWindow);

              

              int i=0;

              m_pACreate3DData=pACreate3DData;

              int iContourNumber=mContourInfo.size();

              int iSizeOfCircle=m_pACreate3DData->GetSize();

              CArray<CONTOURINFO,CONTOURINFO>  aContourInfo;

              if(iContourNumber>0 && iSizeOfCircle>0){

                     

                     map <int, int>::const_iterator  it=mContourInfo.begin();

                     aContourInfo.RemoveAll();

                     for(it=mContourInfo.begin();it!=mContourInfo.end();it++){

                            CONTOURINFO  ItemContourinfo;

                            ItemContourinfo.iContourID=it->first;

                            ItemContourinfo.iLayer=it->second;

                            aContourInfo.Add(ItemContourinfo);

                     }

                     

                     for(int iCounter=0;iCounter<iContourNumber;iCounter++){

                            int iContourId=0;

                            int iCurrentContourLayer=0;

                            int iAPointSequence[DF_MAX_LAYER][DF_MAX_POINTS];

                            CArray<CIRCLE,CIRCLE> TempCreate3DData;

                            CONTOURINFO  ItemContourinfo;

                            

                            ItemContourinfo=aContourInfo.GetAt(iCounter);

                            if(ItemContourinfo.iContourID>0){

                                   iContourId=ItemContourinfo.iContourID;

                                   iCurrentContourLayer=ItemContourinfo.iLayer;

                            }

                     

                            TempCreate3DData.RemoveAll();

                            for(int
iCounterCircle=0;iCounterCircle<iSizeOfCircle;iCounterCircle++){

                                   CIRCLE  circleTemp;

                                  
circleTemp=m_pACreate3DData->GetAt(iCounterCircle);

                                   if(circleTemp.IDContour==iContourId){

                                          TempCreate3DData.Add(circleTemp);

                                   }

                            }

                            

                            if(iCurrentContourLayer<DF_MAX_LAYER){

                                   long iCount=0;

                                   int iSize=TempCreate3DData.GetSize();

                                   for(int
iTemp=0;iTemp<TempCreate3DData.GetSize();iTemp++){

                                         
if(TempCreate3DData.GetAt(iTemp).pData->GetSize()<DF_MAX_POINTS)

                                                 for(int
iPoints=0;iPoints<TempCreate3DData.GetAt(iTemp).pData->GetSize();iPoints++)

                                                       
iAPointSequence[iTemp][iPoints]=iCount++;

                                   }

                            }

                            

                            vtkPoints *points=vtkPoints::New();

                            if(points==NULL)  throw("Points is Null");

                            long iCouterPoints=0;

                            for(int
iTemp=0;iTemp<TempCreate3DData.GetSize();iTemp++){

                                   for(int
j=0;j<TempCreate3DData.GetAt(iTemp).pData->GetSize();j++){

                                          CPoint pt;

                                         
pt=TempCreate3DData.GetAt(iTemp).pData->GetAt(j);

                                          int ix=(int)pt.x;

                                          int iy=(int)pt.y;

                                         
points->InsertPoint(iCouterPoints++, ix, iy,
TempCreate3DData.GetAt(iTemp).fLayer);

                                         
OutPutFloat(TempCreate3DData.GetAt(iTemp).fLayer);

                                   }

                            }

                            

                            vtkCellArray *lines=vtkCellArray::New();

                            if(lines==NULL)   throw("lines is Null");

                            for(int iCouterCell=0
;iCouterCell<TempCreate3DData.GetSize();iCouterCell++)

                                  
lines->InsertNextCell(TempCreate3DData.GetAt(iCouterCell).pData->GetSize(),iAPointSequence[iCouterCell]);

                            

                                                        vtkPolyData
*profile=vtkPolyData::New();

                            if(profile==NULL) throw("profile is Null");

                            profile->SetPoints(points);

                            if(points!=NULL)  points->Delete();

                            profile->SetLines(lines);

                            profile->SetPolys(lines);

                            profile->SetVerts(lines);

                            if(lines!=NULL)  lines->Delete();

                            

          /*    vtkKitwareContourFilter 
*pKitwareContourFilter=vtkKitwareContourFilter::New();

                            pKitwareContourFilter->SetInput(profile);

                            pKitwareContourFilter->SetValue(0, 1);

                            pKitwareContourFilter->Update();*/

                            

                            

                            vtkLinearExtrusionFilter
*extrude=vtkLinearExtrusionFilter::New();

                            if(extrude==NULL) throw("extrude is Null");

                            extrude->SetInput(profile);

                            if(profile!=NULL) profile->Delete();

                            extrude->SetScaleFactor(5);

                            extrude->SetVector(0 ,0,1);

                            extrude->CappingOff();

                            

                            //vtkContourFilter
*lineContours=vtkContourFilter::New();

                            //ineContours->SetInput(extrude->GetOutput());

                            //neContours->SetValue(0,0);

                            

                            //映射数据

                            vtkPolyDataMapper *cubeMapper =
vtkPolyDataMapper::New();

                            //     cubeMapper->SetInput(cube);

                            cubeMapper->SetInput(extrude->GetOutput());

                            if(extrude!=NULL) extrude->Delete();

                            //     cubeMapper->SetScalarRange(0,1);

                            //创建演员

                            vtkActor *cubeActor = vtkActor::New();

                            if(cubeActor!=NULL){

                                   cubeActor->SetMapper(cubeMapper);

                                   if(cubeMapper!=NULL) cubeMapper->Delete();

                                   cubeActor->GetProperty()->SetOpacity(1);

                                  
cubeActor->GetProperty()->SetColor(1.00,0.388,0.2784);

                            }

                            else{

                                   throw("this->pActor::New()
Failure......................");

                            }

                            this->pRenderer->AddActor(cubeActor);

                            if(cubeActor!=NULL)  cubeActor->Delete();

                     }

                     this->pRenderer->SetBackground(0,0,0);

                     /*

                    
this->pRenderer->SetBackground(this->m_stctDislayProperty.faBackground[0],

                     this->m_stctDislayProperty.faBackground[1],

                     this->m_stctDislayProperty.faBackground[2]);

                     */

                    
this->pRenderWindow->SetSize(this->m_stctDislayProperty.sizeWindow.cx,

                            this->m_stctDislayProperty.sizeWindow.cy);

                     

                     if ( !this->pWindowInteractor->GetInitialized()){    

                            this->pWindowInteractor->Initialize();

                     }

                     // Note:underside row codes  only have one row  

                     this->pRenderWindow->Render();

                     //this->pWindowInteractor->Start();

                     this->m_stctCreate3DType=CREATE_CONTOURING_3D;

              }

              

              //reserve

              /*

              vtkCamera *camera = vtkCamera::New();

              camera->SetPosition(1,0,1);

              camera->SetFocalPoint(0,0,0);

              camera->ComputeViewPlaneNormal();

              camera->OrthogonalizeViewUp();

              camera->SetViewUp(0,0,1);

              renderer->AddActor(cubeActor);

              renderer->SetActiveCamera(camera);

              renderer->ResetCamera();

              renderer->SetBackground(0,0,0);

              camera->Dolly(1);*/

              

              }

              catch (char szError[]){

                     OutPut(szError);

                     return RETURN_FAILURE;     

              }

       

       return RETURN_SUCCESS;

 

}



Best regard!
join
13760346716
0755-83509390
sz_chenhongwei at yahoo.com.cn         
szjoin at gmail.com
msn:cw1982519 at msn.com
Copyright (c) 2005, YPSUN Ltd,.Co All rights reserved.



More information about the vtkusers mailing list