Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CMake/CheckCxxStandard.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Check if user has specified C++ 11 or newer
# using the old style flags.
# (this does not check Compiler's capability)

string(FIND "${CMAKE_CXX_FLAGS}" "c++11" FLAG_FOUND)

if (NOT FLAG_FOUND EQUAL -1)
MESSAGE(STATUS "CXX_STANDARD: Found c++11 in CMAKE_CXX_FLAGS")
string(REPLACE "-std=c++11" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-std=gnu++11" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_STANDARD 11)
set(USING_CPP11 1)

elseif ((CMAKE_CXX_STANDARD EQUAL 11) OR (CMAKE_CXX_STANDARD GREATER 11))
MESSAGE(STATUS "CXX_STANDARD: User specified CMAKE_CXX_STANDARD " ${CMAKE_CXX_STANDARD})
set(USING_CPP11 1)

else()
MESSAGE(STATUS "CXX_STANDARD: default (C++98)")
endif()
12 changes: 12 additions & 0 deletions CMake/RequiresCxxVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
macro(Requires_CxxVersion example version_min)
if ((CMAKE_CXX_STANDARD EQUAL 11) OR (CMAKE_CXX_STANDARD GREATER 11))
# Compile this example
else()
# If variable is not set or less than 11:
message(STATUS "VTKWikiExamples: ${example} requires C++${version_min} or newer")
string(REGEX REPLACE "[^;]*${example}.cxx"
"" ALL_FILES "${ALL_FILES}")
string(REGEX REPLACE "[^;]*${example}.ui"
"" ALL_UI_FILES "${ALL_UI_FILES}")
endif()
endmacro()
2 changes: 2 additions & 0 deletions CMake/RequiresVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ macro(Requires_Version example version_min)
message(STATUS "VTKWikiExamples: ${example} requires VTK version ${version_min} or newer but the current version is ${VTK_VERSION}")
string(REGEX REPLACE "[^;]*${example}.cxx"
"" ALL_FILES "${ALL_FILES}")
string(REGEX REPLACE "[^;]*${example}.ui"
"" ALL_UI_FILES "${ALL_UI_FILES}")
endif()
endmacro()
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(WikiExamples)

# VTK follows the C++03 standard
#set(CMAKE_CXX_STANDARD 11) # Compile examples that require C++11

# Check if C++11 was enabled in flags
include(${WikiExamples_SOURCE_DIR}/CMake/CheckCxxStandard.cmake)

# Display type of build
set(_msg "VTKWikiExamples: Building VTKWikiExamples stand-alone")
message(STATUS "${_msg}")
Expand Down
9 changes: 9 additions & 0 deletions src/Cxx/Developers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ else()
endif()
#

if (USING_CPP11)
# vtkTest.cxx needs C++11
add_executable(AlgorithmFilter AlgorithmFilter vtkTestAlgorithmFilter vtkTest)
target_link_libraries(AlgorithmFilter ${VTK_LIBRARIES})

add_executable(AlgorithmSource AlgorithmSource vtkTestAlgorithmSource vtkTest1)
target_link_libraries(AlgorithmSource ${VTK_LIBRARIES})
endif()

if(NOT ${VTK_VERSION} VERSION_EQUAL "7.0.0")
# Does not compile with VTK 7.0.0
add_executable(ProgressReport ProgressReport.cxx vtkTestProgressReportFilter.cxx)
target_link_libraries(ProgressReport ${VTK_LIBRARIES})
endif()

add_executable(FilterSelfProgress FilterSelfProgress.cxx vtkTestFilterSelfProgressFilter.cxx)
target_link_libraries(FilterSelfProgress ${VTK_LIBRARIES})
Expand All @@ -36,5 +42,8 @@ target_link_libraries(GraphAlgorithmSource ${VTK_LIBRARIES})
add_executable(ImageAlgorithmFilter ImageAlgorithmFilter vtkImageAlgorithmFilter.cxx)
target_link_libraries(ImageAlgorithmFilter ${VTK_LIBRARIES})

if(NOT ${VTK_VERSION} VERSION_EQUAL "7.0.0")
# Does not compile with VTK 7.0.0
add_executable(MultipleInputPorts MultipleInputPorts vtkTestMultipleInputPortsFilter)
target_link_libraries(MultipleInputPorts ${VTK_LIBRARIES})
endif()
22 changes: 22 additions & 0 deletions src/Cxx/GeometricObjects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,33 @@ set(KIT_LIBS ${VTK_LIBRARIES})
# Build all .cxx files in the directory
file(GLOB ALL_FILES *.cxx)

# VTK follows the C++03 standard but some examples require C++11
include(${WikiExamples_SOURCE_DIR}/CMake/RequiresCxxVersion.cmake)
Requires_CxxVersion(Cell3DDemonstration 11 ALL_FILES)
Requires_CxxVersion(GeometricObjectsDemo 11 ALL_FILES)
Requires_CxxVersion(Hexahedron 11 ALL_FILES)
Requires_CxxVersion(IsoparametricCellsDemo 11 ALL_FILES)
Requires_CxxVersion(OrientedArrow 11 ALL_FILES)
Requires_CxxVersion(OrientedCylinder 11 ALL_FILES)
Requires_CxxVersion(ParametricKuenDemo 11 ALL_FILES)
Requires_CxxVersion(ParametricObjects 11 ALL_FILES)
Requires_CxxVersion(ParametricObjectsDemo2 11 ALL_FILES)
Requires_CxxVersion(ParametricObjectsDemo 11 ALL_FILES)
Requires_CxxVersion(ParametricSuperEllipsoidDemo 11 ALL_FILES)
Requires_CxxVersion(ParametricSuperToroidDemo 11 ALL_FILES)
Requires_CxxVersion(Plane 11 ALL_FILES)
Requires_CxxVersion(PolyLine1 11 ALL_FILES)
Requires_CxxVersion(SourceObjectsDemo 11 ALL_FILES)

include(${WikiExamples_SOURCE_DIR}/CMake/RequiresVersion.cmake)
set(VERSION_MIN "7.0")
Requires_Version(ParametricKuenDemo ${VERSION_MIN} ALL_FILES)
Requires_Version(ParametricObjectsDemo2 ${VERSION_MIN} ALL_FILES)

Requires_Version(QuadraticHexahedronDemo "7.1.0" ALL_FILES)
Requires_Version(QuadraticTetraDemo "7.1.0" ALL_FILES)
Requires_Version(CellTypeSource "8.0.0" ALL_FILES)

foreach(SOURCE_FILE ${ALL_FILES})
string(REPLACE ".cxx" "" TMP ${SOURCE_FILE})
string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR}/ "" EXAMPLE ${TMP})
Expand Down
8 changes: 4 additions & 4 deletions src/Cxx/GeometricObjects/CellTypeSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ int main (int argc, char *argv[])
vtkSmartPointer<vtkMinimalStandardRandomSequence> rng =
vtkSmartPointer<vtkMinimalStandardRandomSequence>::New();
rng->SetSeed(5070); // for testing
for (auto i = 0; i <points->GetNumberOfPoints(); ++i)
for (vtkIdType i = 0; i <points->GetNumberOfPoints(); ++i)
{
double perturbation[3];
for (auto j = 0; j < 3; ++j)
for (vtkIdType j = 0; j < 3; ++j)
{
rng->Next();
perturbation[j] = rng->GetRangeValue(-0.1,0.1);
Expand All @@ -103,12 +103,12 @@ int main (int argc, char *argv[])
}
source->GetOutput()->SetPoints(points);

int numCells = source->GetOutput()->GetNumberOfCells();
vtkIdType numCells = source->GetOutput()->GetNumberOfCells();
std::cout << "Number of cells: " << numCells << std::endl;
vtkSmartPointer<vtkIntArray> idArray =
vtkSmartPointer<vtkIntArray>::New();
idArray->SetNumberOfTuples(numCells);
for (auto i = 0; i < numCells; ++i)
for (vtkIdType i = 0; i < numCells; ++i)
{
idArray->InsertTuple1(i, i + 1);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Cxx/GeometricObjects/EllipticalCylinder.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkLinearExtrusionFilter.h>
#include <vtkMath.h>
#include <vtkNamedColors.h>
#include <vtkPoints.h>
#include <vtkPolyDataMapper.h>
Expand Down
2 changes: 2 additions & 0 deletions src/Cxx/GeometricObjects/EllipticalCylinderDemo.cxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <vtkActor.h>
#include <vtkArrowSource.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkLinearExtrusionFilter.h>
#include <vtkMath.h>
#include <vtkNamedColors.h>
#include <vtkPoints.h>
#include <vtkPolyDataMapper.h>
Expand Down
1 change: 1 addition & 0 deletions src/Cxx/GeometricObjects/ParametricKuenDemo.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <vtkActor.h>
#include <vtkActor2D.h>
#include <vtkCamera.h>
#include <vtkCommand.h>
#include <vtkMath.h>
#include <vtkNamedColors.h>
#include <vtkParametricFunctionSource.h>
Expand Down
37 changes: 20 additions & 17 deletions src/Cxx/GeometricObjects/Planes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ int main(int, char* [])
vtkSmartPointer<vtkNamedColors>::New();

// These are the two methods we will use.
std::vector<std::string> titles{"Using frustum planes", "Using bounds"};
std::vector<vtkSmartPointer<vtkPlanes>> planes;
for (auto i = 0; i < titles.size(); ++i)
std::vector<std::string> titles;
titles.push_back("Using frustum planes");
titles.push_back("Using bounds");

std::vector<vtkSmartPointer<vtkPlanes> > planes;
for (std::vector<std::string>::size_type i = 0; i < titles.size(); ++i)
{
planes.push_back(vtkSmartPointer<vtkPlanes>::New());
}
Expand Down Expand Up @@ -66,15 +69,15 @@ int main(int, char* [])
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iRen->SetRenderWindow(renWin);

std::vector<vtkSmartPointer<vtkHull>> hulls;
std::vector<vtkSmartPointer<vtkPolyData>> pds;
std::vector<vtkSmartPointer<vtkPolyDataMapper>> mappers;
std::vector<vtkSmartPointer<vtkActor>> actors;
std::vector<vtkSmartPointer<vtkTextMapper>> textMappers;
std::vector<vtkSmartPointer<vtkActor2D>> textActors;
std::vector<vtkSmartPointer<vtkRenderer>> renderers;
std::vector<vtkSmartPointer<vtkHull> > hulls;
std::vector<vtkSmartPointer<vtkPolyData> > pds;
std::vector<vtkSmartPointer<vtkPolyDataMapper> > mappers;
std::vector<vtkSmartPointer<vtkActor> > actors;
std::vector<vtkSmartPointer<vtkTextMapper> > textMappers;
std::vector<vtkSmartPointer<vtkActor2D> > textActors;
std::vector<vtkSmartPointer<vtkRenderer> > renderers;

for (auto i = 0; i < titles.size(); ++i)
for (std::vector<std::string>::size_type i = 0; i < titles.size(); ++i)
{
hulls.push_back(vtkSmartPointer<vtkHull>::New());
hulls[i]->SetPlanes(planes[i]);
Expand Down Expand Up @@ -115,16 +118,16 @@ int main(int, char* [])
}

// Setup the viewports
auto xGridDimensions = 2;
auto yGridDimensions = 1;
auto rendererSize = 300;
const int xGridDimensions = 2;
const int yGridDimensions = 1;
const int rendererSize = 300;
renWin->SetSize(rendererSize * xGridDimensions,
rendererSize * yGridDimensions);
for (auto row = 0; row < yGridDimensions; ++row)
for (int row = 0; row < yGridDimensions; ++row)
{
for (auto col = 0; col < xGridDimensions; ++col)
for (int col = 0; col < xGridDimensions; ++col)
{
auto index = row * xGridDimensions + col;
const int index = row * xGridDimensions + col;

// (xmin, ymin, xmax, ymax)
double viewport[4] = {
Expand Down
35 changes: 20 additions & 15 deletions src/Cxx/GeometricObjects/PlatonicSolids.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ int main(int, char* [])
lut->SetTableValue(18, 0.4, 0, 0);
lut->SetTableValue(19, 0.4, 0, 0.4);

std::vector<vtkSmartPointer<vtkPolyDataMapper>> mappers;
std::vector<vtkSmartPointer<vtkActor>> actors;
std::vector<vtkSmartPointer<vtkTextMapper>> textMappers;
std::vector<vtkSmartPointer<vtkActor2D>> textActors;
std::vector<vtkSmartPointer<vtkRenderer>> renderers;
std::vector<vtkSmartPointer<vtkPolyDataMapper> > mappers;
std::vector<vtkSmartPointer<vtkActor> > actors;
std::vector<vtkSmartPointer<vtkTextMapper> > textMappers;
std::vector<vtkSmartPointer<vtkActor2D> > textActors;
std::vector<vtkSmartPointer<vtkRenderer> > renderers;

// Create a common text property.
vtkSmartPointer<vtkTextProperty> textProperty =
Expand All @@ -71,10 +71,15 @@ int main(int, char* [])
iRen->SetRenderWindow(renWin);

// There are five platonic solids.
std::vector<std::string> names{"Tetrahedron", "Cube", "Octahedron",
"Icosahedron", "Dodecahedron"};
std::vector<vtkSmartPointer<vtkPlatonicSolidSource>> PlatonicSolids;
for (auto i = 0; i < names.size(); ++i)
std::vector<std::string> names;
names.push_back("Tetrahedron");
names.push_back("Cube");
names.push_back("Octahedron");
names.push_back("Icosahedron");
names.push_back("Dodecahedron");

std::vector<vtkSmartPointer<vtkPlatonicSolidSource> > PlatonicSolids;
for (std::vector<std::string>::size_type i = 0; i < names.size(); ++i)
{
PlatonicSolids.push_back(vtkSmartPointer<vtkPlatonicSolidSource>::New());
PlatonicSolids[i]->SetSolidType(i);
Expand Down Expand Up @@ -103,16 +108,16 @@ int main(int, char* [])
}

// Setup the viewports
auto xGridDimensions = 3;
auto yGridDimensions = 2;
auto rendererSize = 300;
const int xGridDimensions = 3;
const int yGridDimensions = 2;
const int rendererSize = 300;
renWin->SetSize(rendererSize * xGridDimensions,
rendererSize * yGridDimensions);
for (auto row = 0; row < yGridDimensions; ++row)
for (int row = 0; row < yGridDimensions; ++row)
{
for (auto col = 0; col < xGridDimensions; ++col)
for (int col = 0; col < xGridDimensions; ++col)
{
auto index = row * xGridDimensions + col;
const int index = row * xGridDimensions + col;

// (xmin, ymin, xmax, ymax)
double viewport[4] = {
Expand Down
4 changes: 2 additions & 2 deletions src/Cxx/GeometricObjects/QuadraticHexahedron.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ vtkSmartPointer<vtkUnstructuredGrid> MakeQuadraticHexahedron()
vtkSmartPointer<vtkMinimalStandardRandomSequence>::New();
points->SetNumberOfPoints(aHexahedron->GetNumberOfPoints());
rng->SetSeed(5070); // for testing
for (auto i = 0; i < aHexahedron->GetNumberOfPoints(); ++i)
for (vtkIdType i = 0; i < aHexahedron->GetNumberOfPoints(); ++i)
{
double perturbation[3];
for (auto j = 0; j < 3; ++j)
for (vtkIdType j = 0; j < 3; ++j)
{
rng->Next();
perturbation[j] = rng->GetRangeValue(-0.1, 0.1);
Expand Down
4 changes: 2 additions & 2 deletions src/Cxx/GeometricObjects/QuadraticHexahedronDemo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ vtkSmartPointer<vtkUnstructuredGrid> MakeQuadraticHexahedron()
vtkSmartPointer<vtkMinimalStandardRandomSequence>::New();
points->SetNumberOfPoints(aHexahedron->GetNumberOfPoints());
rng->SetSeed(5070); // for testing
for (auto i = 0; i < aHexahedron->GetNumberOfPoints(); ++i)
for (vtkIdType i = 0; i < aHexahedron->GetNumberOfPoints(); ++i)
{
double perturbation[3];
for (auto j = 0; j < 3; ++j)
for (vtkIdType j = 0; j < 3; ++j)
{
rng->Next();
perturbation[j] = rng->GetRangeValue(-0.1, 0.1);
Expand Down
4 changes: 2 additions & 2 deletions src/Cxx/GeometricObjects/QuadraticTetra.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ vtkSmartPointer<vtkUnstructuredGrid> MakeQuadraticTetra()
vtkSmartPointer<vtkMinimalStandardRandomSequence>::New();
points->SetNumberOfPoints(aTetra->GetNumberOfPoints());
rng->SetSeed(5070); // for testing
for (auto i = 0; i < aTetra->GetNumberOfPoints(); ++i)
for (vtkIdType i = 0; i < aTetra->GetNumberOfPoints(); ++i)
{
double perturbation[3];
for (auto j = 0; j < 3; ++j)
for (vtkIdType j = 0; j < 3; ++j)
{
rng->Next();
perturbation[j] = rng->GetRangeValue(-0.1, 0.1);
Expand Down
4 changes: 2 additions & 2 deletions src/Cxx/GeometricObjects/QuadraticTetraDemo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ vtkSmartPointer<vtkUnstructuredGrid> MakeQuadraticTetra()
vtkSmartPointer<vtkMinimalStandardRandomSequence>::New();
points->SetNumberOfPoints(aTetra->GetNumberOfPoints());
rng->SetSeed(5070); // for testing
for (auto i = 0; i < aTetra->GetNumberOfPoints(); ++i)
for (vtkIdType i = 0; i < aTetra->GetNumberOfPoints(); ++i)
{
double perturbation[3];
for (auto j = 0; j < 3; ++j)
for (vtkIdType j = 0; j < 3; ++j)
{
rng->Next();
perturbation[j] = rng->GetRangeValue(-0.2, 0.2);
Expand Down
1 change: 1 addition & 0 deletions src/Cxx/HyperTreeGrid/HyperTreeGridSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkNamedColors.h>

int main( int, char*[] )
Expand Down
11 changes: 11 additions & 0 deletions src/Cxx/IO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ file(GLOB ALL_FILES *.cxx)

include(${WikiExamples_SOURCE_DIR}/CMake/RequiresGitLfs.cmake)

# VTK follows the C++03 standard but some examples require C++11
include(${WikiExamples_SOURCE_DIR}/CMake/RequiresCxxVersion.cmake)
Requires_CxxVersion(ImageWriter 11 ALL_FILES)

include(${WikiExamples_SOURCE_DIR}/CMake/RequiresVersion.cmake)
Requires_Version(VRMLImporterDemo "7.1.0" ALL_FILES)
Requires_Version(ExportPolyDataScene "8.0.0" ALL_FILES)
Requires_Version(ImportPolyDataScene "8.0.0" ALL_FILES)
Requires_Version(OBJImporter "8.0.0" ALL_FILES)
Requires_Version(ImageWriter "8.1.0" ALL_FILES)

Requires_GitLfs(DEMReader ALL_FILES)

foreach(SOURCE_FILE ${ALL_FILES})
Expand Down
1 change: 1 addition & 0 deletions src/Cxx/IO/ImageWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <vtkTIFFWriter.h>
#include <vtkWindowToImageFilter.h>

#include <algorithm>
#include <array>
#include <locale>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/Cxx/IO/ReadAllPolyDataTypesDemo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main (int argc, char *argv[])
// Setup render window
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
std::vector<vtkSmartPointer<vtkRenderer>> renderers;
std::vector<vtkSmartPointer<vtkRenderer> > renderers;
for (int i = 1; i < argc; ++i)
{
vtkSmartPointer<vtkPolyData> polyData =
Expand Down
Loading