Commit ca073466 authored by Ken Martin's avatar Ken Martin

in progress

Change-Id: I9f2bafb8707c86180a0893280474c101593cc9c0
parent 738b812b
......@@ -76,8 +76,8 @@ int TestPDBBallAndStick(int argc, char *argv[])
double firstRender = timer->GetElapsedTime();
cerr << "first render time: " << firstRender << endl;
/*
int numRenders = 15;
int numRenders = 85;
timer->StartTimer();
for (int i = 0; i < numRenders; ++i)
{
......@@ -96,7 +96,7 @@ int TestPDBBallAndStick(int argc, char *argv[])
ren->GetActiveCamera()->Zoom(1.7);
win->Render();
*/
// Finally render the scene and compare the image to a reference image
win->SetMultiSamples(0);
win->GetInteractor()->Initialize();
......
......@@ -10,6 +10,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
FrustumClip.cxx
Mace.cxx
RGrid.cxx
vtkCmbGlyphMappingTest3.cxx,NO_VALID
TestActor2DTextures.cxx
TestActorLightingFlag.cxx
TestAnimationScene.cxx
......
/*=========================================================================
Copyright (c) 1998-2005 Kitware Inc. 28 Corporate Drive, Suite 204,
Clifton Park, NY, 12065, USA.
All rights reserved. No part of this software may be reproduced,
distributed,
or modified, in any form or by any means, without permission in writing from
Kitware Inc.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkSmartPointer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleSwitch.h"
#include "vtkCmbGlyphPointSource.h"
#include "vtkGlyph3DMapper.h"
#include "vtkCylinderSource.h"
#include "vtkCamera.h"
#include <string>
#include "vtkTesting.h"
#include "vtkTimerLog.h"
#include "vtkNew.h"
#include "vtkCmbGlyphPointSource.cxx"
//----------------------------------------------------------------------------
// Tests Glyph Point Source's individual property settings
int vtkCmbGlyphMappingTest3(int argc, char *argv[])
{
int n = 300;
vtkSmartPointer<vtkTesting> testHelper = vtkSmartPointer<vtkTesting>::New();
testHelper->AddArguments(argc,const_cast<const char **>(argv));
vtkNew<vtkTimerLog> timer;
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(800,800);
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindowInteractor> iren;
vtkNew<vtkInteractorStyleSwitch> style;
style->SetCurrentStyleToTrackballCamera();
iren->SetInteractorStyle( style.GetPointer() );
iren->SetRenderWindow(renWin.GetPointer());
renWin->AddRenderer( renderer.GetPointer() );
vtkNew<vtkCmbGlyphPointSource> points;
// Lets create some points
int i, j, vis;
double x, y, s, delta = 1.0;
double start = -0.5 * delta * n;
vtkIdType id;
int k;
int pointCount = 0;
for (j = 0, y = start; j < n; j++, y+=delta)
{
for (i = 0, x = start; i < n; i++, x+=delta)
{
vis = 1;
s = 10;
k = i+j;
if ((k % 2) == 0)
{
id = points->InsertNextPoint(x, 0.0, y);
points->SetGlyphType(id, 0);
points->SetColor(id, 1.0, 0.0, 0.0, 1.0);
points->SetVisibility(id, vis);
points->SetScale(id, 1.0, s, 1.0);
id = points->InsertNextPoint(x, 0.0, y);
points->SetGlyphType(id, 1);
points->SetColor(id, 1.0, 1.0, 0.0, 1.0);
points->SetVisibility(id, vis);
points->SetScale(id, 1, s*.99, 1);
pointCount += 2;
}
else if ((k % 3) == 0)
{
id = points->InsertNextPoint(x, 0.0, y);
points->SetGlyphType(id, 3);
points->SetColor(id, 1.0, 0.7, 0.0, 1.0);
points->SetVisibility(id, vis);
points->SetScale(id, 1, s, 1);
pointCount++;
}
else
{
id = points->InsertNextPoint(x, 0.0, y);
points->SetGlyphType(id, 2);
points->SetColor(id, 0.5, 1.0, 0.5, 1.0);
points->SetVisibility(id, vis);
points->SetScale(id, 1, s, 1);
pointCount++;
}
}
}
vtkNew<vtkCylinderSource> cyl;
cyl->CappingOn();
cyl->SetRadius(0.2);
cyl->SetResolution(18);
cyl->Update();
vtkNew<vtkCylinderSource> cyl1;
cyl1->CappingOn();
cyl1->SetRadius(0.4);
cyl1->SetResolution(18);
cyl1->Update();
vtkNew<vtkCylinderSource> cyl2;
cyl2->CappingOn();
cyl2->SetRadius(0.4);
cyl2->SetResolution(18);
cyl2->Update();
vtkNew<vtkCylinderSource> cyl3;
cyl3->CappingOn();
cyl3->SetRadius(0.3);
cyl3->SetResolution(18);
cyl3->Update();
int polygons = pointCount*cyl->GetOutput()->GetPolys()->GetNumberOfCells();
vtkNew<vtkGlyph3DMapper> mapper;
mapper->SetSourceConnection(0, cyl->GetOutputPort() );
mapper->SetSourceConnection(1, cyl1->GetOutputPort() );
mapper->SetSourceConnection(2, cyl2->GetOutputPort() );
mapper->SetSourceConnection(3, cyl3->GetOutputPort() );
mapper->SetInputConnection(points->GetOutputPort());
mapper->SetMaskArray("Visibility");
mapper->SetOrientationArray("Orientation");
mapper->SetScaleArray("Scaling");
mapper->SetSourceIndexArray("GlyphType");
mapper->SetMasking(true);
if (!testHelper->IsFlagSpecified("-N"))
{
mapper->SetSourceIndexing(true);
mapper->SetRange(0.0,3.0);
}
mapper->SetOrientationModeToRotation();
mapper->SetScaleModeToScaleByVectorComponents();
vtkNew<vtkActor> actor;
actor->SetMapper( mapper.GetPointer() );
renderer->AddViewProp( actor.GetPointer() );
renderer->ResetCamera();
timer->StartTimer();
iren->Initialize();
renWin->Render();
timer->StopTimer();
cout << "First frame time: " << timer->GetElapsedTime() << "\n";
timer->StartTimer();
for (i = 0; i <= 100; i++)
{
renderer->GetActiveCamera()->Elevation(0.9);
renderer->GetActiveCamera()->Zoom(1.02);
renWin->Render();
}
timer->StopTimer();
double t = timer->GetElapsedTime();
cout << "Avg Frame time: " << t/100.0 << " Frame Rate: " << 100.0 / t << "\n";
cout << " polygons: " << polygons << " Mpolys/sec: " << 100.0*polygons/(1000000.0*t) << "\n";
int retVal = vtkTesting::PASSED;
if (testHelper->IsFlagSpecified("-V"))
{
testHelper->SetRenderWindow(renWin.GetPointer());
retVal = testHelper->RegressionTest(10);
}
if (testHelper->IsInteractiveModeSpecified())
{
iren->Start();
}
return (retVal == vtkTesting::PASSED) ? 0 : 1;
}
/*=========================================================================
Copyright (c) 1998-2012 Kitware Inc. 28 Corporate Drive,
Clifton Park, NY, 12065, USA.
All rights reserved. No part of this software may be reproduced,
distributed,
or modified, in any form or by any means, without permission in writing from
Kitware Inc.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkCmbGlyphPointSource.h"
#include "vtkPolyData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkUnsignedCharArray.h"
#include "vtkDoubleArray.h"
#include "vtkPointData.h"
#include "vtkBitArray.h"
#include "vtkIntArray.h"
#include "vtkCellArray.h"
#include "vtkNew.h"
#include "vtkPolyDataWriter.h"
#include "vtkPolyDataReader.h"
#include "vtkTransform.h"
#include "vtkBoundingBox.h"
vtkStandardNewMacro(vtkCmbGlyphPointSource);
//-----------------------------------------------------------------------------
vtkCmbGlyphPointSource::vtkCmbGlyphPointSource()
{
vtkPointData *pdata;
this->Source = vtkSmartPointer<vtkPolyData>::New();
pdata = this->Source->GetPointData();
this->Points = vtkSmartPointer<vtkPoints>::New();
this->Points->SetDataTypeToDouble();
this->Source->SetPoints(this->Points);
this->CellIds = vtkSmartPointer<vtkCellArray>::New();
this->Source->SetVerts(this->CellIds);
// Make sure that there is an element in
// the cell array
this->CellIds->InsertNextCell(0);
// Add color information
this->Color = vtkSmartPointer<vtkUnsignedCharArray>::New();
this->Color->SetName("Color");
this->Color->SetNumberOfComponents(4);
pdata->AddArray(this->Color);
// Add Scaling information
this->Scaling = vtkSmartPointer<vtkDoubleArray>::New();
this->Scaling->SetName("Scaling");
this->Scaling->SetNumberOfComponents(3);
pdata->AddArray(this->Scaling);
// Add Orientation information
this->Orientation = vtkSmartPointer<vtkDoubleArray>::New();
this->Orientation->SetName("Orientation");
this->Orientation->SetNumberOfComponents(3);
pdata->AddArray(this->Orientation);
// Add Visibility information
this->Visibility = vtkSmartPointer<vtkBitArray>::New();
this->Visibility->SetName("Visibility");
this->Visibility->SetNumberOfComponents(1);
pdata->AddArray(this->Visibility);
// Add Glyph Type information
this->GlyphType = vtkSmartPointer<vtkIntArray>::New();
this->GlyphType->SetName("GlyphType");
this->GlyphType->SetNumberOfComponents(1);
pdata->AddArray(this->GlyphType);
// Add Color Uniqueness information
this->SelectionMask = vtkSmartPointer<vtkBitArray>::New();
this->SelectionMask->SetName("UniqueColor");
this->SelectionMask->SetNumberOfComponents(1);
pdata->AddArray(this->SelectionMask);
// Set Colors to be the active scalar array
pdata->SetActiveScalars("Color");
// Set the default color to be white
this->DefaultColor[0] = this->DefaultColor[1] = this->DefaultColor[2] =
this->DefaultColor[3] = 1.0;
// Create a tranform that can be re-used
this->Transform = vtkSmartPointer<vtkTransform>::New();
this->SetNumberOfInputPorts(0);
}
//-----------------------------------------------------------------------------
vtkCmbGlyphPointSource::~vtkCmbGlyphPointSource()
{
this->Source = NULL;
this->Points = NULL;
this->Color = NULL;
this->Scaling = NULL;
this->Orientation = NULL;
this->Visibility = NULL;
this->SelectionMask = NULL;
this->CellIds = NULL; // Array should be deleted with PolyData
this->Transform = NULL;
}
//-----------------------------------------------------------------------------
int vtkCmbGlyphPointSource::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
// get the ouptut
vtkPolyData *output = vtkPolyData::GetData(outputVector, 0);
// now move the input through to the output
output->ShallowCopy( this->Source );
return 1;
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Source: " << this->Source << "\n";
os << indent << "Points: " << this->Points << "\n";
os << indent << "Color: " << this->Color << "\n";
os << indent << "Scaling: " << this->Scaling << "\n";
os << indent << "Orientation: " << this->Orientation << "\n";
os << indent << "Visibility: " << this->Visibility << "\n";
os << indent << "SelectionMask: " << this->SelectionMask << "\n";
os << indent << "Default Color: " << this->DefaultColor[0]
<< ", " << this->DefaultColor[1] << ", " << this->DefaultColor[2]
<< ", " << this->DefaultColor[3] << "\n";
}
//-----------------------------------------------------------------------------
vtkIdType vtkCmbGlyphPointSource::InsertNextPoint(double x, double y, double z)
{
vtkIdType id = this->Points->InsertNextPoint(x, y, z);
this->Points->GetBounds(this->GlyphSourceBounds);
this->Color->InsertNextTuple4((255.0*this->DefaultColor[0])+0.5,
(255.0*this->DefaultColor[1])+0.5,
(255.0*this->DefaultColor[2])+0.5,
(255.0*this->DefaultColor[3])+0.5);
this->Scaling->InsertNextTuple3(1.0, 1.0, 1.0);
this->Orientation->InsertNextTuple3(0.0, 0.0, 0.0);
this->Visibility->InsertNextValue(1);
this->GlyphType->InsertNextValue(0);
this->SelectionMask->InsertNextValue(0);
// Update the vertices point Ids
this->CellIds->InsertCellPoint(id);
this->CellIds->UpdateCellCount(id+1);
this->Modified();
return id;
}
//-----------------------------------------------------------------------------
vtkIdType
vtkCmbGlyphPointSource::InsertNextPoint(double x, double y, double z,
double r, double g, double b, double a,
double sx, double sy, double sz,
double ox, double oy, double oz,
int vis)
{
vtkIdType id = this->Points->InsertNextPoint(x, y, z);
this->Points->GetBounds(this->GlyphSourceBounds);
this->Color->InsertNextTuple4((255.0*r)+0.5, (255.0*g)+0.5, (255.0*b)+0.5,
(255.0*a)+0.5);
this->Scaling->InsertNextTuple3(sx, sy, sz);
this->Orientation->InsertNextTuple3(ox, oy, oz);
this->Visibility->InsertNextValue(vis);
// Update the vertices point Ids
this->CellIds->InsertCellPoint(id);
this->CellIds->UpdateCellCount(id+1);
this->SelectionMask->InsertNextValue(1);
this->Modified();
return id;
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::SetScale(vtkIdType index, double sx, double sy,
double sz)
{
this->Scaling->SetTuple3(index, sx, sy, sz);
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::SetOrientation(vtkIdType index, double ox,
double oy, double oz)
{
this->Orientation->SetTuple3(index, ox, oy, oz);
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::SetVisibility(vtkIdType index, int flag)
{
this->Visibility->SetValue(index, flag);
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::SetGlyphType(vtkIdType index, int type)
{
this->GlyphType->SetValue(index, type);
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::SetColor(vtkIdType index, double r, double g,
double b, double a)
{
this->Color->SetTuple4(index, (255.0*r)+0.5, (255.0*g)+0.5, (255.0*b)+0.5,
(255.0*a)+0.5);
this->SelectionMask->SetValue(index, 1);
this->Color->Modified();
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::UnsetColor(vtkIdType index)
{
this->Color->SetTuple4(index,
(255.0*this->DefaultColor[0])+0.5,
(255.0*this->DefaultColor[1])+0.5,
(255.0*this->DefaultColor[2])+0.5,
(255.0*this->DefaultColor[3])+0.5);
this->SelectionMask->SetValue(index, 0);
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::SetDefaultColor(double r, double g,
double b, double a)
{
this->DefaultColor[0] = r;
this->DefaultColor[1] = g;
this->DefaultColor[2] = b;
this->DefaultColor[3] = a;
unsigned char rb = (255.0*r)+0.5;
unsigned char gb = (255.0*g)+0.5;
unsigned char bb = (255.0*b)+0.5;
unsigned char ab = (255.0*a)+0.5;
vtkIdType i, n = this->Color->GetNumberOfTuples();
for (i = 0; i < n; i++)
{
if (!this->SelectionMask->GetValue(i))
{
this->Color->SetTuple4(i, rb, gb, bb, ab);
}
}
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::ApplyTransform(double *odelta, double *pdelta ,
double *sdelta)
{
double val[3];
vtkIdType i, n = this->Points->GetNumberOfPoints();
for (i = 0; i < n; i++)
{
this->Points->GetPoint(i, val);
val[0] += pdelta[0];
val[1] += pdelta[1];
val[2] += pdelta[2];
this->Points->SetPoint(i, val);
this->Orientation->GetTuple(i, val);
val[0] += odelta[0];
val[1] += odelta[1];
val[2] += odelta[2];
this->Orientation->SetTuple(i, val);
this->Scaling->GetTuple(i, val);
val[0] *= sdelta[0];
val[1] *= sdelta[1];
val[2] *= sdelta[2];
this->Scaling->SetTuple(i, val);
}
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::ApplyTransform(vtkIdType i,
double *odelta, double *pdelta,
double *sdelta)
{
double val[3];
this->Points->GetPoint(i, val);
val[0] += pdelta[0];
val[1] += pdelta[1];
val[2] += pdelta[2];
this->Points->SetPoint(i, val);
this->Orientation->GetTuple(i, val);
val[0] += odelta[0];
val[1] += odelta[1];
val[2] += odelta[2];
this->Orientation->SetTuple(i, val);
this->Scaling->GetTuple(i, val);
val[0] *= sdelta[0];
val[1] *= sdelta[1];
val[2] *= sdelta[2];
this->Scaling->SetTuple(i, val);
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::ResetColorsToDefault()
{
unsigned char rb = (255.0*this->DefaultColor[0])+0.5;
unsigned char gb = (255.0*this->DefaultColor[1])+0.5;
unsigned char bb = (255.0*this->DefaultColor[2])+0.5;
unsigned char ab = (255.0*this->DefaultColor[3])+0.5;
vtkIdType i, n = this->Color->GetNumberOfTuples();
for (i = 0; i < n; i++)
{
if (this->SelectionMask->GetValue(i))
{
this->Color->SetTuple4(i, rb, gb, bb, ab);
this->SelectionMask->SetValue(i, 0);
}
}
this->Modified();
}
//-----------------------------------------------------------------------------
void vtkCmbGlyphPointSource::SetPoint(vtkIdType index,
double x, double y, double z)
{