[vtkusers] Resampling unstructured points

Stefano Perticoni stperti at infinito.it
Wed Jun 20 06:52:45 EDT 2001


Hello Todd,

here is a program i use to resample an ugrid with a cutting plane.
You can change the orientation of the cutting plane by changing the
orientation of the normale to the cutting plane.
The attach is the output for a mesh made up of two tetra.

Stefano

//*******************************************************************

#include .h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"

#include "vtkUnstructuredGridReader.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPlane.h"
#include "vtkCutter.h"

#include "vtkDataSetMapper.h"
#include "vtkPolyDataMapper.h"
#include "vtkTextMapper.h"
#include "vtkScalarsToColors.h"
#include "vtkLookupTable.h"

#include "vtkActor.h"
#include "vtkScaledTextActor.h"

#include "vtkWindowToImageFilter.h"
#include "vtkBMPWriter.h"

#include <string>
#include <iostream>
#include <fstream>


void main( int argc, char *argv[] )
{
  bool plotTheGrid=true;
  bool plotTheCuttingPlane=false;
  bool plotTheWire=false;
  bool plotTheTitle=true;
  char* scalarName="Density";
  double gridOpacity=1.; // 0: transparent, 1: opaque
  double xPlane=0.5,yPlane=0.5,zPlane=0.5;// origin of the cutting plane
  double nxPlane=1,nyPlane=-1,nzPlane=1;  // normale to the cutting plane
  //----------------------------------------------------------------------
  int i;
  bool save;
  char file_name[256];
  if( (argc == 3) && (strcmp("-S", argv[1]) == 0) ){
    save = true;
    sprintf(file_name,argv[2]);
  }else{
    if(argc == 2){
      save = false;
      sprintf(file_name,argv[1]);
    } else {
      cout << "usage pptk file  or pptk -S file" << endl;
      exit(1);
    }
  }
  cout << "loading: " << file_name << endl;
  //
  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(renderer);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  vtkUnstructuredGridReader *ugridreader = vtkUnstructuredGridReader::New();
  ugridreader->SetFileName(file_name);
  ugridreader->SetScalarsName(scalarName);

  vtkDataSetMapper *ugridMapper = vtkDataSetMapper::New();
  ugridMapper->ScalarVisibilityOn();
  ugridMapper->SetInput(ugridreader->GetOutput());
  ugridMapper->Update();
  ugridMapper->SetScalarRange(ugridreader->GetOutput()->GetScalarRange());
  //================================
  // I reverse the color table in order to use blue for the lowest values
  // and red for the highest
  vtkLookupTable *lutdefault = vtkLookupTable::New();
  vtkLookupTable *lutreverse = vtkLookupTable::New();
  int nbcol = 256;
  lutdefault->SetNumberOfColors(nbcol);
  lutdefault->SetHueRange(0.0 ,.66667);
  lutdefault->SetSaturationRange(1.0,1.0);
  lutdefault->SetTableRange(0.0,1.0);
  lutdefault->SetValueRange(1.0,1.0);
  lutdefault->SetAlphaRange(1.0,1.0);
  lutdefault->Build();
  lutreverse->SetNumberOfColors(nbcol);
  for(int idx=0;idx<nbcol;idx++)
    lutreverse->SetTableValue(idx,lutdefault->GetTableValue(nbcol-idx));
  //================================
  ugridMapper->SetLookupTable(lutreverse);
  // Actor : ugridActor

  vtkActor *ugridActor = vtkActor::New();
  ugridActor->SetMapper(ugridMapper);
  ugridActor->GetProperty()->SetColor(1.0,0.7,0.7);
  ugridActor->GetProperty()->SetOpacity(gridOpacity);
  ugridActor->AddPosition(0,0.001,0);

  // Actor : wireActor
  vtkActor *wireActor = vtkActor::New();
  wireActor->SetMapper(ugridMapper);
  wireActor->GetProperty()->SetRepresentationToWireframe();
  wireActor->GetProperty()->SetColor(1,1,1);

  // TextMapper: titleMapper
  vtkTextMapper *titleMapper = vtkTextMapper::New();
  titleMapper->SetInput(ugridreader->GetHeader());
  titleMapper->SetJustificationToCentered();

  // TextActor: titleActor
  vtkScaledTextActor *titleActor = vtkScaledTextActor::New();
  titleActor->SetMapper(titleMapper);
  titleActor->GetProperty()->SetColor(0.,1,0);
  titleActor->GetPositionCoordinate()->
    SetCoordinateSystemToNormalizedViewport();

  // titleActor->GetPositionCoordinate()->SetValue(0.5,0.92);
  // plane
  vtkPlane *plane = vtkPlane::New();
  plane->SetOrigin(xPlane,yPlane,zPlane);
  plane->SetNormal(nxPlane,nyPlane,nzPlane);
  // cutter
  vtkCutter* cutter = vtkCutter::New();
  cutter->SetInput(ugridreader->GetOutput());
  cutter->SetCutFunction(plane);
  // cutter mapper
  vtkPolyDataMapper* cutterMapper = vtkPolyDataMapper::New();
  cutterMapper->SetInput(cutter->GetOutput());
  cutterMapper->Update();
  cutterMapper->SetScalarRange(ugridreader->GetOutput()->GetScalarRange());
  cutterMapper->SetLookupTable(lutreverse);
  // cutter actor
  vtkActor* cut = vtkActor::New();
  cut->SetMapper(cutterMapper);

  if(plotTheGrid) renderer->AddActor(ugridActor);
  if(plotTheWire) renderer->AddActor(wireActor);
  if(plotTheCuttingPlane) renderer->AddActor(cut);
  if(plotTheTitle) renderer->AddActor(titleActor);
  //
  renderer->SetBackground(0,0,0);
  //renderer->ResetCamera();
  // interact with data
  renWin->SetSize(600,400);
  renWin->Render();
  if(save){
    char save_filename[1024];
    vtkWindowToImageFilter *w2bmp = vtkWindowToImageFilter::New();
    vtkBMPWriter *rtbmpw = vtkBMPWriter::New();
    sprintf( save_filename, "%s.bmp", file_name );
    w2bmp->SetInput(renWin);
    rtbmpw->SetInput(w2bmp->GetOutput());
    rtbmpw->SetFileName(save_filename);
    rtbmpw->Write();
    cout << "save "<< save_filename << endl;
    exit(0);
  } else {
    iren->Start();
  }
}
//*************************************************************************
----- Original Message -----
From: "TJ Wilkinson" <tswilkin at fas.harvard.edu>
To: <vtkusers at public.kitware.com>
Sent: Tuesday, June 19, 2001 10:09 PM
Subject: [vtkusers] Resampling unstructured points


> I have a cloud of unstructured 3D points forming a surface of a volume.  I
> would like to extract a new set of points in a plane intersecting this
> closed surface at an arbitrary orientation.
>
> Please, please could someone point me in the right direction (e.g. tell
> me what data structures and filters to use)?
>
> Thanks.
>
> Todd
>
>
>
>




-------------- next part --------------
A non-text attachment was scrubbed...
Name: cutting.jpg
Type: image/jpeg
Size: 7096 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20010620/bb600981/attachment.jpg>


More information about the vtkusers mailing list