[vtkusers] Re: fastest way to precache orthogonal slices of a volume?

jose manjon jmanjon at fis.upv.es
Wed Jan 29 04:41:30 EST 2003


> I use this and it works well enough, hope this helps:

// I create ORTHOGONAL VIEWER here

void CRenderView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
  // ORTHOGONAL VIEWER

        unsigned short * p;
  C3DFrame* frame;
     CImageView* v1;
     CImageView* v2;
     CImageView* v3;
        CACRNEMAViewerDoc *pDoc = (CACRNEMAViewerDoc *) GetDocument();
  frame=((C3DFrame*)GetParentFrame());
      v1=frame->GetView(0,1);
     v2=frame->GetView(1,0);
     v3=frame->GetView(1,1);
     int nx=v1->IA;
     int ny=v2->IA;
  int nz=v3->IA;


  lut=vtkLookupTable::New();
  lut->SetNumberOfColors(256);
  double B,G,R;
  for(int i=0;i<1024;i=i+4)
  {
    B=(double)v1->ani->m_pDIB[40+i]/255;
    G=(double)v1->ani->m_pDIB[40+i+1]/255;
    R=(double)v1->ani->m_pDIB[40+i+2]/255;
          if(i/4<opacidad) lut->SetTableValue(i/4,R,G,B,0);
    else lut->SetTableValue(i/4,R,G,B,1);
  }
  lut->SetTableRange(0,255);

  /////////// PLANO AXIAL  /////////////////////////////////////////////////////

  datos1=vtkStructuredPoints::New();
  datos1->SetDimensions(v1->ani->Columns,v1->ani->Rows,1);
  datos1->SetScalarType(VTK_UNSIGNED_SHORT);
  datos1->SetNumberOfScalarComponents(1);
  datos1->AllocateScalars();
        p=(unsigned short *) datos1->GetScalarPointer();
  for(int y=0;y<v1->ani->Rows;y++)
  for(int x=0;x<v1->ani->Columns;x++)
  {
     *p++ = v1->ani->Bitmap[y*v1->ani->Columns+x];
  }
        plane1=vtkPlaneSource::New();
  plane1->SetNormal(0,0,1);
        planeMapper1=vtkPolyDataMapper::New();
        planeMapper1->SetInput(plane1->GetOutput());
        text1=vtkTexture::New();
  text1->SetInput(datos1);
        text1->SetLookupTable(lut);
  text1->InterpolateOn();
  planeActor1=vtkActor::New();
        planeActor1->SetMapper(planeMapper1);
  planeActor1->SetTexture(text1);

  /////////// PLANO CORONAL  /////////////////////////////////////////////////////

  datos2=vtkStructuredPoints::New();
  datos2->SetDimensions(pDoc->m_ani[0].Columns,pDoc->fuentes,1);
  datos2->SetScalarType(VTK_UNSIGNED_SHORT);
  datos2->SetNumberOfScalarComponents(1);
  datos2->AllocateScalars();
        p=(unsigned short *) datos2->GetScalarPointer();
  for(y=0;y<v2->ani->Rows;y++)
  for(int x=0;x<v2->ani->Columns;x++)
  {
     *p++ = v2->ani->Bitmap[y*v2->ani->Columns+v2->ani->Columns-1-x];
  }

        double yr=((double)pDoc->fuentes/(double)pDoc->m_ani[0].Rows)/2.0;
  yr=yr*(pDoc->resz/pDoc->resx);

  plane2=vtkPlaneSource::New();
  plane2->SetNormal(0,1,0);
        plane2->SetOrigin(-0.5,0,-yr);
        plane2->SetPoint1(0.5,0,-yr);
        plane2->SetPoint2(-0.5,0,yr);
        plane2->SetXResolution(1);
        plane2->SetYResolution(1);
        planeMapper2=vtkPolyDataMapper::New();
        planeMapper2->SetInput(plane2->GetOutput());
  text2=vtkTexture::New();
  text2->SetInput(datos2);
  text2->SetLookupTable(lut);
        text2->InterpolateOn();
        planeActor2=vtkActor::New();
        planeActor2->SetMapper(planeMapper2);
        planeActor2->SetTexture(text2);

  /////////// PLANO SAGITAL /////////////////////////////////////////////////////

  datos3=vtkStructuredPoints::New();
  datos3->SetDimensions(pDoc->m_ani[0].Columns,pDoc->fuentes,1);
  datos3->SetScalarType(VTK_UNSIGNED_SHORT);
  datos3->SetNumberOfScalarComponents(1);
  datos3->AllocateScalars();
        p=(unsigned short *) datos3->GetScalarPointer();
  for(y=0;y<v3->ani->Rows;y++)
  for(int x=0;x<v3->ani->Columns;x++)
  {
     *p++ = v3->ani->Bitmap[y*v3->ani->Columns+v3->ani->Columns-1-x];
  }
  plane3=vtkPlaneSource::New();
  plane3->SetNormal(1,0,0);
  plane3->SetOrigin(0,-0.5,-yr);
        plane3->SetPoint1(0, 0.5,-yr);
        plane3->SetPoint2(0,-0.5, yr);
        plane3->SetXResolution(1);
        plane3->SetYResolution(1);
        planeMapper3=vtkPolyDataMapper::New();
        planeMapper3->SetInput(plane3->GetOutput());
        text3=vtkTexture::New();
  text3->SetInput(datos3);
  text3->SetLookupTable(lut);
  text3->InterpolateOn();
  planeActor3=vtkActor::New();
        planeActor3->SetMapper(planeMapper3);
        planeActor3->SetTexture(text3);

        /////////// CUBO  /////////////////////////////////////////////////////

  vtkCubeSource * cube=vtkCubeSource::New();
  cube->SetBounds(-0.5,0.5,-0.5,0.5,-yr,yr);
  vtkPolyDataMapper *cubeMapper=vtkPolyDataMapper::New();
        cubeMapper->SetInput(cube->GetOutput());
  vtkActor *cubeActor=vtkActor::New();
        cubeActor->SetMapper(cubeMapper);
  cubeActor->GetProperty()->SetRepresentationToWireframe();

  /////////// RENDER /////////////////////////////////////////////////////

  this->Renderer->SetBackground(0.05,0.15,0.45);

  this->Renderer->AddActor(planeActor1);
  this->Renderer->AddActor(planeActor2);
  this->Renderer->AddActor(planeActor3);
  this->Renderer->AddActor(cubeActor);

  vtkCamera * cam=this->Renderer->GetActiveCamera();
  cam->Elevation(90);
  cam->Azimuth(180);

  // I put many lights

        vtkLight *light1 = vtkLight::New();
        light1->SetPosition(1,0,1);

        vtkLight *light2 = vtkLight::New();
        light2->SetPosition(0,1,1);

        vtkLight *light3 = vtkLight::New();
        light3->SetPosition(-1,0,1);

        vtkLight *light4 = vtkLight::New();
        light4->SetPosition(0,-1,1);

        this->Renderer->AddLight(light1);
        this->Renderer->AddLight(light2);
        this->Renderer->AddLight(light3);
        this->Renderer->AddLight(light4);

  cube->Delete();
  cubeMapper->Delete();
  cubeActor->Delete();

  }

jose

--
##########################################################

         Prof.  Jose Vicente Manjón Herrera

         Dept. Fisica Aplicada
         Escuela Universitaria de Informatica
         Universidad Politécnica de Valencia (SPAIN)

##########################################################





More information about the vtkusers mailing list