/* This file is part of Lemma, a geophysical modelling and inversion API. * More information is available at http://lemmasoftware.org */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * @file * @date 08/07/2014 04:16:25 PM * @version $Id$ * @author Trevor Irons (ti) * @email Trevor.Irons@xri-geo.com * @copyright Copyright (c) 2014, XRI Geophysics, LLC * @copyright Copyright (c) 2014, Trevor Irons */ #include #include #include #include #include #include #include #include int main(int argc, char**argv) { std::cout << "Mesh processing routine\n"; if (argc<3) { std::cout << "usage:\n" << "./utVTKEdge inMesh.vtu outG.vtu" << std::endl; } vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New(); std::cout << "Reading" << argv[1] << std::endl; Reader->SetFileName(argv[1]); Reader->Update(); int nc = Reader->GetOutput()->GetNumberOfCells() ; int nn = Reader->GetOutput()->GetNumberOfPoints() ; std::cout << "Processing grid with nodes=" << nn << "\t cells=" << nc << "\n"; // Input magnet size TODO get from file or .geo file even? double R = .25; // radius of magnet double D0 = 10; // Top of magnet double D1 = 11; // Bottom of magnet double eps = 1e-2; // epsilon for on the point // Pol = double[3]; // Declare new array for the data vtkDoubleArray* G = vtkDoubleArray::New(); G->SetNumberOfComponents(1); G->SetNumberOfTuples(nn); G->SetName("G"); // Loop over nodes, look at position, set with G if on boundary double point[3]; for (int in=0; inGetOutput()->GetPoint(in, &point[0]); //std::cout << point[0] << "\t" < R - eps && raddist < R + eps && point[2] < D1 && point[2] > D0 ) { if ( point[1] < 0 ) { G->InsertTuple1( in, 1 ); } else if (point[1] > 0) { G->InsertTuple1( in, -1 ); } else { G->InsertTuple1( in, 0 ); } } else { G->InsertTuple1( in, 0 ); } } // Add new data Reader->GetOutput()->GetPointData()->SetScalars( G ); // Write out new file vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New(); Writer->SetInputConnection(Reader->GetOutputPort()); Writer->SetFileName( argv[2] ); Writer->Write(); Reader->Delete(); }