2015-09-23 20:43:27 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2015-09-23 20:43:27 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2015-09-23 20:43:27 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
|
2015-11-02 21:22:35 +00:00
|
|
|
#ifndef VTKM_DEVICE_ADAPTER
|
|
|
|
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
|
|
|
|
#endif
|
|
|
|
|
2015-09-23 20:43:27 +00:00
|
|
|
#include <vtkm/cont/CellSetExplicit.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
2016-01-15 20:42:51 +00:00
|
|
|
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/filter/Triangulate.h>
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2015-10-08 17:38:56 +00:00
|
|
|
//Suppress warnings about glut being deprecated on OSX
|
2016-01-12 14:00:07 +00:00
|
|
|
#if (defined(VTKM_GCC) || defined(VTKM_CLANG))
|
2017-05-18 14:29:41 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
2015-10-08 17:38:56 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <GLUT/glut.h>
|
2015-09-23 20:43:27 +00:00
|
|
|
#else
|
2017-05-18 14:29:41 +00:00
|
|
|
#include <GL/glut.h>
|
2015-09-23 20:43:27 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-10 17:46:17 +00:00
|
|
|
using DeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG;
|
2015-09-23 20:43:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2015-11-03 14:10:39 +00:00
|
|
|
|
2015-09-23 20:43:27 +00:00
|
|
|
// Takes input uniform grid and outputs unstructured grid of triangles
|
2017-02-14 22:37:58 +00:00
|
|
|
static vtkm::cont::DataSet outDataSet;
|
|
|
|
static vtkm::Id numberOfInPoints;
|
2015-09-23 20:43:27 +00:00
|
|
|
|
2015-11-03 14:10:39 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2015-09-23 20:43:27 +00:00
|
|
|
//
|
|
|
|
// Construct an input data set with uniform grid of indicated dimensions, origin and spacing
|
|
|
|
//
|
|
|
|
vtkm::cont::DataSet MakeTriangulateExplicitDataSet()
|
|
|
|
{
|
2016-01-18 21:19:48 +00:00
|
|
|
vtkm::cont::DataSetBuilderExplicitIterative builder;
|
2016-05-13 18:26:59 +00:00
|
|
|
builder.Begin();
|
2016-01-18 21:19:48 +00:00
|
|
|
|
|
|
|
builder.AddPoint(0, 0, 0); // 0
|
|
|
|
builder.AddPoint(1, 0, 0); // 1
|
|
|
|
builder.AddPoint(2, 0, 0); // 2
|
|
|
|
builder.AddPoint(3, 0, 0); // 3
|
|
|
|
builder.AddPoint(0, 1, 0); // 4
|
|
|
|
builder.AddPoint(1, 1, 0); // 5
|
|
|
|
builder.AddPoint(2, 1, 0); // 6
|
|
|
|
builder.AddPoint(3, 1, 0); // 7
|
|
|
|
builder.AddPoint(0, 2, 0); // 8
|
|
|
|
builder.AddPoint(1, 2, 0); // 9
|
|
|
|
builder.AddPoint(2, 2, 0); // 10
|
|
|
|
builder.AddPoint(3, 2, 0); // 11
|
|
|
|
builder.AddPoint(0, 3, 0); // 12
|
|
|
|
builder.AddPoint(3, 3, 0); // 13
|
|
|
|
builder.AddPoint(1, 4, 0); // 14
|
|
|
|
builder.AddPoint(2, 4, 0); // 15
|
|
|
|
|
|
|
|
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
|
|
|
|
builder.AddCellPoint(0);
|
|
|
|
builder.AddCellPoint(1);
|
|
|
|
builder.AddCellPoint(5);
|
|
|
|
|
|
|
|
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
|
|
|
|
builder.AddCellPoint(1);
|
|
|
|
builder.AddCellPoint(2);
|
|
|
|
builder.AddCellPoint(6);
|
|
|
|
builder.AddCellPoint(5);
|
|
|
|
|
|
|
|
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
|
|
|
|
builder.AddCellPoint(5);
|
|
|
|
builder.AddCellPoint(6);
|
|
|
|
builder.AddCellPoint(10);
|
|
|
|
builder.AddCellPoint(9);
|
|
|
|
|
|
|
|
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
|
|
|
|
builder.AddCellPoint(4);
|
|
|
|
builder.AddCellPoint(5);
|
|
|
|
builder.AddCellPoint(9);
|
|
|
|
builder.AddCellPoint(8);
|
|
|
|
|
|
|
|
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
|
|
|
|
builder.AddCellPoint(2);
|
|
|
|
builder.AddCellPoint(3);
|
|
|
|
builder.AddCellPoint(7);
|
|
|
|
|
|
|
|
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
|
|
|
|
builder.AddCellPoint(6);
|
|
|
|
builder.AddCellPoint(7);
|
|
|
|
builder.AddCellPoint(11);
|
|
|
|
builder.AddCellPoint(10);
|
|
|
|
|
|
|
|
builder.AddCell(vtkm::CELL_SHAPE_POLYGON);
|
|
|
|
builder.AddCellPoint(9);
|
|
|
|
builder.AddCellPoint(10);
|
|
|
|
builder.AddCellPoint(13);
|
|
|
|
builder.AddCellPoint(15);
|
|
|
|
builder.AddCellPoint(14);
|
|
|
|
builder.AddCellPoint(12);
|
|
|
|
|
|
|
|
return builder.Create();
|
2015-09-23 20:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize the OpenGL state
|
|
|
|
//
|
|
|
|
void initializeGL()
|
|
|
|
{
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(-0.5f, 3.5f, -0.5f, 4.5f, -1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Render the output using simple OpenGL
|
|
|
|
//
|
|
|
|
void displayCall()
|
|
|
|
{
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glLineWidth(3.0f);
|
|
|
|
|
|
|
|
// Get cell set and the number of cells and vertices
|
2016-01-14 19:01:05 +00:00
|
|
|
vtkm::cont::CellSetSingleType<> cellSet;
|
|
|
|
outDataSet.GetCellSet(0).CopyTo(cellSet);
|
2015-09-23 20:43:27 +00:00
|
|
|
vtkm::Id numberOfCells = cellSet.GetNumberOfCells();
|
|
|
|
|
2017-12-12 19:26:23 +00:00
|
|
|
auto vertexArray = outDataSet.GetCoordinateSystem().GetData();
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
// Draw the two triangles belonging to each quad
|
|
|
|
vtkm::Float32 color[4][3] = {
|
2017-05-18 14:29:41 +00:00
|
|
|
{ 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 0.0f }
|
2015-09-24 16:56:03 +00:00
|
|
|
};
|
2015-09-23 20:43:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::Id triangle = 0; triangle < numberOfCells; triangle++)
|
|
|
|
{
|
2015-09-23 20:43:27 +00:00
|
|
|
vtkm::Id indx = triangle % 4;
|
|
|
|
glColor3f(color[indx][0], color[indx][1], color[indx][2]);
|
|
|
|
|
|
|
|
// Get the indices of the vertices that make up this triangle
|
|
|
|
vtkm::Vec<vtkm::Id, 3> triIndices;
|
|
|
|
cellSet.GetIndices(triangle, triIndices);
|
|
|
|
|
|
|
|
// Get the vertex points for this triangle
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<vtkm::Float64, 3> pt0 = vertexArray.GetPortalConstControl().Get(triIndices[0]);
|
|
|
|
vtkm::Vec<vtkm::Float64, 3> pt1 = vertexArray.GetPortalConstControl().Get(triIndices[1]);
|
|
|
|
vtkm::Vec<vtkm::Float64, 3> pt2 = vertexArray.GetPortalConstControl().Get(triIndices[2]);
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
// Draw the triangle filled with alternating colors
|
2017-05-18 14:29:41 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
2015-09-23 20:43:27 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
2017-05-18 14:29:41 +00:00
|
|
|
glVertex3d(pt0[0], pt0[1], pt0[2]);
|
|
|
|
glVertex3d(pt1[0], pt1[1], pt1[2]);
|
|
|
|
glVertex3d(pt2[0], pt2[1], pt2[2]);
|
2015-09-23 20:43:27 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
glFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Triangulate and render explicit grid example
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
std::cout << "TrianguleExplicitGrid Example" << std::endl;
|
2015-11-02 21:22:35 +00:00
|
|
|
|
2015-09-23 20:43:27 +00:00
|
|
|
// Create the input uniform cell set
|
|
|
|
vtkm::cont::DataSet inDataSet = MakeTriangulateExplicitDataSet();
|
2016-01-14 19:01:05 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> inCellSet;
|
|
|
|
inDataSet.GetCellSet(0).CopyTo(inCellSet);
|
2015-09-23 20:43:27 +00:00
|
|
|
|
2015-09-29 17:20:05 +00:00
|
|
|
numberOfInPoints = inCellSet.GetNumberOfPoints();
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
// Convert 2D explicit cells to triangles
|
2017-03-27 23:36:33 +00:00
|
|
|
vtkm::filter::Triangulate triangulate;
|
2018-03-13 15:31:24 +00:00
|
|
|
outDataSet = triangulate.Execute(inDataSet);
|
2015-09-23 20:43:27 +00:00
|
|
|
|
|
|
|
// Render the output dataset of tets
|
|
|
|
glutInit(&argc, argv);
|
|
|
|
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
|
|
|
|
glutInitWindowSize(1000, 1000);
|
|
|
|
glutInitWindowPosition(100, 100);
|
|
|
|
|
|
|
|
glutCreateWindow("VTK-m Explicit Triangulate");
|
|
|
|
|
|
|
|
initializeGL();
|
|
|
|
|
|
|
|
glutDisplayFunc(displayCall);
|
|
|
|
glutMainLoop();
|
|
|
|
|
2017-02-14 22:37:58 +00:00
|
|
|
outDataSet.Clear();
|
2015-09-23 20:43:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-10-08 17:38:56 +00:00
|
|
|
|
2016-01-12 14:00:07 +00:00
|
|
|
#if (defined(VTKM_GCC) || defined(VTKM_CLANG))
|
2017-05-18 14:29:41 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2015-10-08 17:38:56 +00:00
|
|
|
#endif
|