VTK/Examples/Broken/TensorGlyph

From KitwarePublic

Jump to: navigation, search

Needs some discussion - possible an example use case (what kind of data would warrant tensor glyphs?)

TensorGlyph.cxx

#include <vtkActor.h>
#include <vtkImageAccumulate.h>
#include <vtkImageData.h>
#include <vtkImageExtractComponents.h>
#include <vtkJPEGReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkStdString.h>
#include <vtkXYPlotActor.h>
#include <vtkDoubleArray.h>
#include <vtkFieldData.h>
#include <vtkDataObject.h>
#include "vtkXYPlotWidget.h"
#include <vector>
#include <string>
#include <vtkProperty2D.h>
#include <vtkOBJExporter.h>
#include <vtkMath.h>
#include <vtkTensorGlyph.h>
#include <windows.h>
#include <vtkTensorProbeWidget.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolydata.h>
#include <iostream>
#include <vtkSphereSource.h>
#include <fstream>
#include <vtkProperty.h>
#include <vtkPointData.h>
#include <vtkEllipsoidTensorProbeRepresentation.h>
#include <vtkPolyDataNormals.h>
#include <vtkLookupTable.h>
#include <vtkPolyDataReader.h>
#include <vector>
 
int main()
{
    vtkPoints *points = vtkPoints::New();
    vtkCellArray *lines = vtkCellArray::New();
    vtkPolyData *indata = vtkPolyData::New();
    vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
    vtkActor* fiber_actor = vtkActor::New();
    vtkDoubleArray *dbar = vtkDoubleArray::New();
 
    dbar->SetNumberOfTuples(30);
    dbar->SetNumberOfComponents(9);
    points->SetNumberOfPoints(30);
    lines->SetNumberOfCells(30);
 
	points->InsertPoint(0,76.3221,77.55,6.51956);
    points->InsertPoint(1,76.61,77.2565,6.48612);
	points->InsertPoint(2,77.2707,76.61,6.44554);
	points->InsertPoint(3,77.55,76.3049,6.44472);
	points->InsertPoint(4,78.171,75.67,6.4584);
	points->InsertPoint(5,78.49,75.3107,6.42729);
	points->InsertPoint(6,79.3652,74.73,6.28662);
	points->InsertPoint(7,79.43,74.6902,6.27085);
	points->InsertPoint(8,80.37,74.4123,6.08774);
	points->InsertPoint(9,81.31,74.2963,5.9323);
	points->InsertPoint(10,82.25,74.3973,5.75441);
	points->InsertPoint(11,83.19,74.6849,5.56838);
	points->InsertPoint(12,83.2895,74.73,5.55033);
	points->InsertPoint(13,84.13,75.2796,5.26998);
	points->InsertPoint(14,84.8597,75.67,4.98283);
	points->InsertPoint(15,85.07,75.7414,4.87815);
	points->InsertPoint(16,85.8796,75.9221,4.5);
	points->InsertPoint(17,86.01,75.9254,4.48181);
	points->InsertPoint(18,86.95,75.9888,4.24855);
	points->InsertPoint(19,87.89,76.1424,3.92565);
	points->InsertPoint(20,88.83,76.4401,3.55541);
	points->InsertPoint(21,89.208,76.61,3.40762);
	points->InsertPoint(22,89.77,76.8435,3.19217);
	points->InsertPoint(23,90.24,77.08,3);
	points->InsertPoint(24,90.71,77.3165,2.80783);
	points->InsertPoint(25,91.137,77.55,2.62829);
	points->InsertPoint(26,91.65,77.7081,2.48663);
	points->InsertPoint(27,92.59,77.9117,2.30548);
	points->InsertPoint(28,93.53,78.0862,2.1826);
	points->InsertPoint(29,94.47,78.309,2.10463);
    indata->SetPoints(points);
 
    for (int j = 0; j < 30 - 1; j++)
    {
        lines->InsertNextCell(2);
        lines->InsertCellPoint(j);
        lines->InsertCellPoint(j+1);
    }
    indata->SetLines(lines);
	/// Tensors
	dbar->InsertTuple9(0,-1.15233,0.0831558,0.0469417,0.0831558,-1.25721,0.10167,0.0469417,0.10167,-1.10715);
	dbar->InsertTuple9(1,-1.18056,0.0817272,0.016076,0.0817272,-1.32675,0.125833,0.016076,0.125833,-1.15438);
	dbar->InsertTuple9(2,-1.18056,0.0817272,0.016076,0.0817272,-1.32675,0.125833,0.016076,0.125833,-1.15438);
	dbar->InsertTuple9(3,-1.31342,0.111935,-0.00440449,0.111935,-1.46802,0.146335,-0.00440449,0.146335,-1.23429);
	dbar->InsertTuple9(4,-1.16781,0.11122,-0.0141383,0.11122,-1.27693,0.132024,-0.0141383,0.132024,-1.03371);
	dbar->InsertTuple9(5,-1.16781,0.11122,-0.0141383,0.11122,-1.27693,0.132024,-0.0141383,0.132024,-1.03371);
	dbar->InsertTuple9(6,-1.38069,0.109203,0.0092558,0.109203,-1.51715,0.133452,0.0092558,0.133452,-1.21027);
	dbar->InsertTuple9(7,-1.14841,0.0806457,0.0102503,0.0806457,-1.24333,0.112485,0.0102503,0.112485,-1.01725);
	dbar->InsertTuple9(8,-1.27785,0.0802889,0.0196197,0.0802889,-1.43836,0.104699,0.0196197,0.104699,-1.17551);
	dbar->InsertTuple9(9,-1.26986,0.0836072,0.0241984,0.0836072,-1.4978,0.097942,0.0241984,0.097942,-1.21335);
	dbar->InsertTuple9(10,-1.05699,0.060112,0.0458529,0.060112,-1.28513,0.0940801,0.0458529,0.0940801,-1.02758);
	dbar->InsertTuple9(11,-0.964704,0.0572805,0.0509763,0.0572805,-1.14489,0.0669454,0.0509763,0.0669454,-0.928367);
	dbar->InsertTuple9(12,-1.00464,0.0671846,0.0581906,0.0671846,-1.09436,0.0489461,0.0581906,0.0489461,-0.91881);
	dbar->InsertTuple9(13,-1.00464,0.0671846,0.0581906,0.0671846,-1.09436,0.0489461,0.0581906,0.0489461,-0.91881);
	dbar->InsertTuple9(14,-0.971085,0.0852503,0.0733988,0.0852503,-0.997688,0.0158387,0.0733988,0.0158387,-0.849214);
	dbar->InsertTuple9(15,-0.944608,0.0966993,0.0831595,0.0966993,-0.894014,0.00617204,0.0831595,0.00617204,-0.775734);
	dbar->InsertTuple9(16,-0.785812,0.0916522,0.121172,0.0916522,-0.736182,0.0305042,0.121172,0.0305042,-0.654692);
	dbar->InsertTuple9(17,-0.693762,-0.0566788,0.0149712,-0.0566788,-0.801667,0.141928,0.0149712,0.141928,-0.599402);
	dbar->InsertTuple9(18,-0.646071,-0.0535651,0.0342057,-0.0535651,-0.690139,0.121231,0.0342057,0.121231,-0.51701);
	dbar->InsertTuple9(19,-0.637141,-0.0154121,0.0461398,-0.0154121,-0.643877,0.111064,0.0461398,0.111064,-0.454858);
	dbar->InsertTuple9(20,-0.797635,-0.0118148,0.0577259,-0.0118148,-0.75314,0.163008,0.0577259,0.163008,-0.486943);
	dbar->InsertTuple9(21,-0.728966,-0.101022,0.0644036,-0.101022,-0.726058,0.196638,0.0644036,0.196638,-0.424195);
	dbar->InsertTuple9(22,-0.728966,-0.101022,0.0644036,-0.101022,-0.726058,0.196638,0.0644036,0.196638,-0.424195);
	dbar->InsertTuple9(23,-0.758969,-0.168077,0.0708547,-0.168077,-0.719419,0.183585,0.0708547,0.183585,-0.426426);
	dbar->InsertTuple9(24,-0.758969,-0.168077,0.0708547,-0.168077,-0.719419,0.183585,0.0708547,0.183585,-0.426426);
	dbar->InsertTuple9(25,-0.668036,-0.137555,0.116403,-0.137555,-0.656711,0.11256,0.116403,0.11256,-0.401444);
	dbar->InsertTuple9(26,-0.641165,-0.0977955,0.15653,-0.0977955,-0.611978,0.102783,0.15653,0.102783,-0.362042);
	dbar->InsertTuple9(27,-0.613593,-0.0557351,0.160526,-0.0557351,-0.546749,0.113151,0.160526,0.113151,-0.315061);
	dbar->InsertTuple9(28,-0.596296,-0.0287082,0.117801,-0.0287082,-0.506095,0.128824,0.117801,0.128824,-0.285217);
	dbar->InsertTuple9(29,-0.586993,-0.0293374,0.0632765,-0.0293374,-0.518353,0.128487,0.0632765,0.128487,-0.290524);
 
    indata->GetPointData()->SetTensors(dbar);
    mapper->SetInput(indata);
 
    fiber_actor->SetMapper(mapper);
    fiber_actor->GetProperty()->SetLineWidth(3.0);
	fiber_actor->GetProperty()->SetColor(1,0,0);
 
	vtkSphereSource *src = vtkSphereSource::New();
	src->SetThetaResolution(8);
    src->SetPhiResolution(8);
 
	vtkTensorGlyph *epp = vtkTensorGlyph::New();
	epp->SetInput(indata);
	epp->SetSourceConnection(src->GetOutputPort());
	epp->SetScaleFactor(1);
	epp->ClampScalingOn();
	//epp->SymmetricOn();
	epp->ColorGlyphsOff();
	epp->ThreeGlyphsOff();
	epp->ExtractEigenvaluesOn();
	epp->SetColorModeToEigenvalues();
 
 
 
	vtkLookupTable *lut = vtkLookupTable::New();
	lut->SetHueRange(0.667,1);
	vtkPolyDataMapper *map = vtkPolyDataMapper::New();
	map->SetInputConnection(epp->GetOutputPort());
	//map->SetLookupTable(lut);
 
 
	vtkActor *elactor = vtkActor::New();
	elactor->SetMapper(map);
 
 
    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(fiber_actor);
	renderer->AddActor(elactor);
 
    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
     renderWindow->AddRenderer( renderer );
     renderWindow->SetSize(1000,1000);
 
    vtkSmartPointer<vtkRenderWindowInteractor> interactor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
     interactor->SetRenderWindow( renderWindow );
 
  // Initialize the event loop and then start it
    interactor->Initialize();
     interactor->Start(); 
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
PROJECT(TensorGlyph)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(TensorGlyph TensorGlyph.cxx)
TARGET_LINK_LIBRARIES(TensorGlyph vtkHybrid)
Personal tools