[cig-commits] r8951 - cs/benchmark/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Dec 19 12:07:15 PST 2007


Author: luis
Date: 2007-12-19 12:07:15 -0800 (Wed, 19 Dec 2007)
New Revision: 8951

Added:
   cs/benchmark/cigma/trunk/src/VtkUgMeshPart.cpp
   cs/benchmark/cigma/trunk/src/VtkUgMeshPart.h
Log:
Added MeshPart wrapper around vtkUnstructuredGrid

Added: cs/benchmark/cigma/trunk/src/VtkUgMeshPart.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/VtkUgMeshPart.cpp	2007-12-19 20:07:08 UTC (rev 8950)
+++ cs/benchmark/cigma/trunk/src/VtkUgMeshPart.cpp	2007-12-19 20:07:15 UTC (rev 8951)
@@ -0,0 +1,100 @@
+#include <cstdlib>
+#include <cassert>
+#include "VtkUgMeshPart.h"
+
+// ---------------------------------------------------------------------------
+
+cigma::VtkUgMeshPart::
+VtkUgMeshPart()
+{
+    grid = vtkUnstructuredGrid::New();
+    //grid->PrintSelf(std::cout, 0);
+
+    points = 0;
+
+    nno = 0;
+    nsd = 0;
+    coordsArray = 0;
+
+    nel = 0;
+    ndofs = 0;
+    cellArray = 0;
+}
+
+cigma::VtkUgMeshPart::
+~VtkUgMeshPart()
+{
+}
+
+// ---------------------------------------------------------------------------
+
+void cigma::VtkUgMeshPart::set_coordinates(double *coordinates, int nno, int nsd)
+{
+    assert(coordinates != NULL);
+
+    this->nno = nno;
+    this->nsd = nsd;
+
+    coordsArray = vtkDoubleArray::New();
+    coordsArray->SetNumberOfTuples(nno);
+    coordsArray->SetNumberOfComponents(nsd);
+    coordsArray->SetVoidArray(coordinates, nno*nsd, 1);
+    //coordsArray->PrintSelf(std::cout, 0);
+
+    points = vtkPoints::New();
+    points->SetData(coordsArray);
+    //points->SetDataTypeToDouble(); // XXX:
+    //points->PrintSelf(std::cout, 0);
+
+    grid->SetPoints(points);
+    grid->GetPointData()->SetVectors(coordsArray);
+
+}
+
+void cigma::VtkUgMeshPart::set_connectivity(int *connectivity, int nel, int ndofs)
+{
+    assert(connectivity != NULL);
+
+    this->nel = nel;
+    this->ndofs = ndofs;
+
+    cellArray = vtkCellArray::New();
+    for (int e = 0; e < nel; e++)
+    {
+        cellArray->InsertNextCell(ndofs);
+        for (int i = 0; i < ndofs; i++)
+        {
+            cellArray->InsertCellPoint(connectivity[ndofs*e + i]);
+        }
+    }
+    //cellArray->PrintSelf(std::cout, 0);
+
+    if (ndofs == 4) {
+        std::cout << "VTK_TETRA" << std::endl;
+        grid->SetCells(VTK_TETRA, cellArray);
+    } else if (ndofs == 8) {
+        std::cout << "VTK_HEXAHEDRON" << std::endl;
+        grid->SetCells(VTK_HEXAHEDRON, cellArray);
+    } else {
+        assert(false);
+    }
+}
+// ---------------------------------------------------------------------------
+
+bool cigma::VtkUgMeshPart::
+find_cell(double globalPoint[3], int *cellIndex)
+{
+    vtkTetra *cell = vtkTetra::New();
+
+    double tol2 = 1e-6;
+    double weights[4];
+    double pcoords[3];
+    int subId;
+
+    grid->FindCell(globalPoint, cell, 0, tol2, subId, pcoords, weights);
+
+    std::cout << "ID = " << subId << std::endl;
+    std::cout << "REFCOORDS = " << pcoords[0] << " " << pcoords[0] << " " << pcoords[0] << std::endl;
+
+    return false;
+}

Added: cs/benchmark/cigma/trunk/src/VtkUgMeshPart.h
===================================================================
--- cs/benchmark/cigma/trunk/src/VtkUgMeshPart.h	2007-12-19 20:07:08 UTC (rev 8950)
+++ cs/benchmark/cigma/trunk/src/VtkUgMeshPart.h	2007-12-19 20:07:15 UTC (rev 8951)
@@ -0,0 +1,43 @@
+#ifndef __VTK_UG_MESH_PART_H__
+#define __VTK_UG_MESH_PART_H__
+
+#include "vtkUnstructuredGrid.h"
+#include "vtkPoints.h"
+#include "vtkCellType.h"
+#include "vtkCellArray.h"
+#include "vtkPointData.h"
+#include "vtkDoubleArray.h"
+
+#include "vtkTetra.h"
+#include "vtkHexahedron.h"
+
+namespace cigma
+{
+    class VtkUgMeshPart;
+}
+
+class cigma::VtkUgMeshPart
+{
+public:
+    VtkUgMeshPart();
+    ~VtkUgMeshPart();
+
+public:
+    void initialize();
+    void set_coordinates(double *coordinates, int nno, int nsd);
+    void set_connectivity(int *connectivity, int nel, int ndofs);
+
+public:
+    bool find_cell(double globalPoint[3], int *cellIndex);
+
+public:
+    int nno, nsd;
+    int nel, ndofs;
+    vtkUnstructuredGrid *grid;
+    vtkPoints *points;
+    vtkDoubleArray *coordsArray;
+    vtkCellArray *cellArray;
+};
+
+
+#endif



More information about the cig-commits mailing list