#include "vtkCamera.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleSwitch.h"
#include "vtkPolyData.h"
#include "vtkPointSource.h"
#include "vtkRenderer.h"
#include "vtkElevationFilter.h"
#include "vtkPointSpriteMapper.h"
#include "vtkImageGaussianSource.h"
#include "vtkMath.h"
#include "vtkActor.h"
#include "vtkDebugLeaks.h"
#include "vtkProperty.h"
#include "vtkSmartPointer.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
// vtk Testing
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkSphereSource.h"
#include "vtkAppendPolyData.h"
#include <vtksys/SystemTools.hxx>
#include <vtkstd/string>
//#define SPRITES_ON
//#define SPHERES_ON
#define use_glsl 0
#define use_pointsprites 1
//---------------------------------------------------------------------------
//bool SetEnv(const char* name, const char *val, bool overwrite);
//---------------------------------------------------------------------------
int main( int argc, char *argv[] )
{
//
// We are loading Shaders from a custom materials repository, tell
// the vtkXMLShader loading code to search here.
//
//SetEnv("USER_MATERIALS_DIRS", ResourceDir.c_str(), true);
////////////////////////////////////////////////
//
// An array of point sprite sphere glyphs
//
////////////////////////////////////////////////
const double rows = 10;
const double numspheres = rows*rows;
const double Ascaling = 0.1;
const double Bscaling = 1.0 - Ascaling;
vtkPolyData* Sprites = vtkPolyData::New();
vtkPoints* points = vtkPoints::New();
vtkCellArray* verts = vtkCellArray::New();
vtkFloatArray *sizes = vtkFloatArray::New();
points->SetNumberOfPoints(numspheres);
sizes->SetNumberOfTuples(numspheres);
sizes->SetNumberOfComponents(1);
verts->Allocate(numspheres,numspheres);
Sprites->SetPoints(points);
Sprites->SetVerts(verts);
sizes->SetName("PointSizes");
Sprites->GetPointData()->AddArray(sizes);
//
for (int y=0; y<rows; y++) {
for (int x=0; x<rows; x++) {
vtkIdType Id = y*rows+x;
points->SetPoint(Id, x, y, 0.0);
sizes->SetValue(Id, Ascaling + Bscaling*((double)Id/numspheres));
verts->InsertNextCell(1,&Id);
}
}
//
// Colour sprites
//
vtkElevationFilter* SpriteColour = vtkElevationFilter::New();
SpriteColour->SetInput(Sprites);
SpriteColour->SetLowPoint ( 0.0, 0.0, 0.0);
SpriteColour->SetHighPoint( rows, rows, 0.0);
vtkPointSpriteMapper *SpriteMapper = vtkPointSpriteMapper::New();
SpriteMapper->SetRenderModeToPointSprite();
SpriteMapper->SetBlendModeToOcclude();
SpriteMapper->SetDefaultPointSize(64);
SpriteMapper->SetQuadraticPointDistanceAttenuation(1.0, 0.1, 0.0);
SpriteMapper->SetParticleImageFileName("D:/aaa.png");
SpriteMapper->SetParticleImage(NULL);
SpriteMapper->SetInputConnection(SpriteColour->GetOutputPort());
// Create actor and set sprite mapper
vtkActor *SpriteActor = vtkActor::New();
SpriteActor->SetMapper(SpriteMapper);
////////////////////////////////////////////////
//
// An array of Spheres to go alongside sprites
//
////////////////////////////////////////////////
vtkSphereSource *SphereSource = vtkSphereSource::New();
vtkAppendPolyData *SphereAppend = vtkAppendPolyData::New();
for (int y=0; y<rows; y++) {
for (int x=0; x<rows; x++) {
int Id = y*rows+x;
SphereSource->SetCenter(x, y, 1.0);
SphereSource->SetRadius((Ascaling + Bscaling*((double)Id/numspheres))/2.0);
SphereSource->SetThetaResolution(32);
SphereSource->SetPhiResolution(16);
SphereSource->Update();
vtkPolyData *poly = vtkPolyData::New();
poly->DeepCopy(SphereSource->GetOutput());
SphereAppend->AddInput(poly);
poly->Delete();
}
}
//
// Colour spheres
//
vtkElevationFilter* SphereColour = vtkElevationFilter::New();
SphereColour->SetInputConnection(SphereAppend->GetOutputPort());
SphereColour->SetLowPoint ( 0.0, 0.0, 0.0);
SphereColour->SetHighPoint( rows, rows, 0.0);
//
// Polydata mapper
//
vtkPolyDataMapper* SphereMapper = vtkPolyDataMapper::New();
SphereMapper->SetInputConnection(SphereColour->GetOutputPort());
//
// SphereMapper actor
//
vtkActor* SphereActor = vtkActor::New();
SphereActor->SetMapper(SphereMapper);
////////////////////////////////////////////////
// setup renderer etc
////////////////////////////////////////////////
vtkRenderer* ren = vtkRenderer::New();
//#ifdef SPRITES_ON
ren->AddActor(SpriteActor);
//#endif
//#ifdef SPHERES_ON
// ren->AddActor(SphereActor);
//#endif
const double distance = 1.75;
ren->SetBackground(0.0,0.0,0.0);
ren->GetActiveCamera()->SetPosition(distance*(rows+1.0), distance*(rows+1.0), 0.5);
ren->GetActiveCamera()->SetFocalPoint(rows/2.0, rows/2.0, 0.5);
ren->GetActiveCamera()->SetRoll(45.0);
ren->ResetCameraClippingRange();
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->SetSize(512, 512);
renWin->AddRenderer(ren);
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkInteractorStyleSwitch *is = vtkInteractorStyleSwitch::New();
iren->SetInteractorStyle(is);
is->SetCurrentStyleToTrackballCamera();
renWin->Render();
iren->Start();
return 1;
}