pvbrowser manual
Back Content Forward

vtk

Visualize 2D dataset data1.vtk
Visualize 2D dataset data1.vtk

Добавя се QTclVtkWidget в Qt Designer. VTK е 3D библиотека от висок клас, написана на C++, която може да бъде използвана за писане на скриптове с Tcl . Погледнете Документация на VTK и съществуващата литература за подробна документация.

Пример за визуализация на на 2D данни в data1.vtk (surface.tcl)

# create pipeline

#   create a hue lookup table
vtkLookupTable lut
# blue to red
    lut SetHueRange  0.66667 0.0
    lut Build

# create black to white colormap
vtkLookupTable lbw
#  black to white
    lbw SetHueRange  0 0.0
    lbw SetSaturationRange 0 0
    lbw SetValueRange 0 1

vtkStructuredPointsReader reader
    reader SetFileName "data1.vtk"
    reader Update

#reader needed otherwise range 0..1
    set valuerange [[reader GetOutput] GetScalarRange]
    set minv [lindex $valuerange 0]
    set maxv [lindex $valuerange 1]
#    puts "data range  $minv .. $maxv"

    set dims [[reader GetOutput] GetDimensions]
    set dim1 [lindex $dims 0]
    set dim2 [lindex $dims 1]
    set dim3 [lindex $dims 2]
#    puts "dim1 = $dim1 dim2 = $dim2"

# volgende echt nodig ...
# vtkStructuredPointsGeometryFilter plane
vtkImageDataGeometryFilter plane
    plane SetInput [reader GetOutput]
# SetExtent not needed ..

vtkWarpScalar warp
    warp SetInput [plane GetOutput]
    warp UseNormalOn
    warp SetNormal 0.0 0.0 1
    warp SetScaleFactor 1
vtkCastToConcrete caster
    caster SetInput [warp GetOutput]
vtkPolyDataNormals normals
    normals SetInput [caster GetPolyDataOutput]
    normals SetFeatureAngle 60
vtkPolyDataMapper planeMapper
    planeMapper SetInput [normals GetOutput]
    planeMapper SetLookupTable lut
    eval planeMapper SetScalarRange [[reader GetOutput] GetScalarRange]

vtkTransform transform
    transform Scale 0.02 0.02 0.02

vtkActor dataActor
    dataActor SetMapper planeMapper
    dataActor SetUserMatrix [transform GetMatrix]
    renderer AddActor dataActor
    renderer SetBackground 1 1 1
    set cam1 [renderer GetActiveCamera]

$cam1 ParallelProjectionOff

следва data1.vtk:

data1.vtk би могъл да бъде например измерване на профил. Сървъра Ви може да генерира data1.vtk и да обнови екрана Ви, когато има налични нови измервания.

# vtk DataFile Version 2.0
2D scalar data
ASCII

DATASET STRUCTURED_POINTS
DIMENSIONS    20   20    1
ORIGIN   -10.000 -10.000   0.000
SPACING    1.000   1.000   1.000

POINT_DATA     400
SCALARS scalars float
LOOKUP_TABLE default
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0
 0.0 1.5 3.0 3.0 3.0 3.0 3.0 3.0 1.5 0.0 0.0 1.0 2.0 2.0 2.0 2.0 2.0 2.0 1.0 0.0
 0.0 1.5 3.0 4.5 4.5 4.5 4.5 3.0 1.5 0.0 0.0 1.0 2.0 3.0 3.0 3.0 3.0 2.0 1.0 0.0
 0.0 1.5 3.0 4.5 6.0 6.0 4.5 3.0 1.5 0.0 0.0 1.0 2.0 3.0 4.0 4.0 3.0 2.0 1.0 0.0
 0.0 1.5 3.0 4.5 6.0 6.0 4.5 3.0 1.5 0.0 0.0 1.0 2.0 3.0 4.0 4.0 3.0 2.0 1.0 0.0
 0.0 1.5 3.0 4.5 4.5 4.5 4.5 3.0 1.5 0.0 0.0 1.0 2.0 3.0 3.0 3.0 3.0 2.0 1.0 0.0
 0.0 1.5 3.0 3.0 3.0 3.0 3.0 3.0 1.5 0.0 0.0 1.0 2.0 2.0 2.0 2.0 2.0 2.0 1.0 0.0
 0.0 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 0.0 0.0 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.0
 0.0 2.0 4.0 4.0 4.0 4.0 4.0 4.0 2.0 0.0 0.0 0.5 1.0 1.0 1.0 1.0 1.0 1.0 0.5 0.0
 0.0 2.0 4.0 6.0 6.0 6.0 6.0 4.0 2.0 0.0 0.0 0.5 1.0 1.5 1.5 1.5 1.5 1.0 0.5 0.0
 0.0 2.0 4.0 6.0 8.0 8.0 6.0 4.0 2.0 0.0 0.0 0.5 1.0 1.5 2.0 2.0 1.5 1.0 0.5 0.0
 0.0 2.0 4.0 6.0 8.0 8.0 6.0 4.0 2.0 0.0 0.0 0.5 1.0 1.5 2.0 2.0 1.5 1.0 0.5 0.0
 0.0 2.0 4.0 6.0 6.0 6.0 6.0 4.0 2.0 0.0 0.0 0.5 1.0 1.5 1.5 1.5 1.5 1.0 0.5 0.0
 0.0 2.0 4.0 4.0 4.0 4.0 4.0 4.0 2.0 0.0 0.0 0.5 1.0 1.0 1.0 1.0 1.0 1.0 0.5 0.0
 0.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 0.0 0.0 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

Тук са съответните slot функции.

typedef struct // (todo: define your data structure here)
{
  int xangle;
}
DATA;

static int slotInit(PARAM *p, DATA *d)
{
  if(p == NULL || d == NULL) return -1;
  d->xangle = 0;
  pvDownloadFile(p,"data1.vtk");
  //...
  pvVtkTclScript(p,VtkTclWidget1,"surface.tcl");
  pvVtkTclPrintf(p,VtkTclWidget1,"dataActor RotateX %d",0);
  pvVtkTclPrintf(p,VtkTclWidget1,"dataActor RotateY %d",0);
  pvVtkTclPrintf(p,VtkTclWidget1,"renderer Render");
  pvVtkTclPrintf(p,VtkTclWidget1,"reader Modified");
  pvVtkTclPrintf(p,VtkTclWidget1,"reader Update");
  pvVtkTclPrintf(p,VtkTclWidget1,"renderer Render");
  //...
  return 0;
}

static int slotSliderEvent(PARAM *p, int id, DATA *d, int val)
{
  if(p == NULL || id == 0 || d == NULL || val < -1000) return -1;
  if(id == Slider1)
  {
    int delta;
    delta = (val-50)*3 - d->xangle;
    d->xangle += delta;
    pvVtkTclPrintf(p,VtkTclWidget1,"reader SetFileName \"data1.vtk\"");
    pvVtkTclPrintf(p,VtkTclWidget1,"reader Modified");
    pvVtkTclPrintf(p,VtkTclWidget1,"reader Update");
    pvVtkTclPrintf(p,VtkTclWidget1,"dataActor RotateX %d",delta);
    pvVtkTclPrintf(p,VtkTclWidget1,"renderer Render");
  }
  return 0;
}

Back Content Forward