MOAB: Mesh Oriented datABase  (version 5.5.0)
crop_vol_test.cpp File Reference
#include "moab/Core.hpp"
#include <iostream>
#include <fstream>
#include <cstring>
#include "moab/FBEngine.hpp"
#include "moab/GeomTopoTool.hpp"
#include "TestUtil.hpp"
+ Include dependency graph for crop_vol_test.cpp:

Go to the source code of this file.

Functions

ErrorCode volume_test (FBEngine *pFacet)
 
void handle_error_code (ErrorCode rv, int &number_failed, int &number_successful)
 
int main (int argc, char *argv[])
 

Variables

std::string filename_top
 
std::string filename_bot
 
std::string polygon_file_name
 
double min_dot = 0.8
 
std::string vol_file
 
int number_tests_successful = 0
 
int number_tests_failed = 0
 

Function Documentation

◆ handle_error_code()

void handle_error_code ( ErrorCode  rv,
int &  number_failed,
int &  number_successful 
)

Definition at line 36 of file crop_vol_test.cpp.

37 {
38  if( rv == MB_SUCCESS )
39  {
40  std::cout << "Success";
41  number_successful++;
42  }
43  else
44  {
45  std::cout << "Failure";
46  number_failed++;
47  }
48 }

References MB_SUCCESS.

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 50 of file crop_vol_test.cpp.

51 {
52  filename_bot = TestDir + "unittest/BedCrop2.h5m";
53  filename_top = TestDir + "unittest/SECrop2.h5m"; //"/polyPB.txt";
54  polygon_file_name = TestDir + "unittest/poly14.txt";
55  vol_file = "volIce.h5m"; // output
56 
58  bool remove_output = true;
59 
60  if( argc == 1 )
61  {
62  std::cout << "Using default input files: " << filename_bot << " " << filename_top << " " << polygon_file_name
63  << " " << min_dot << " " << vol_file << std::endl;
64  std::cout << " default output file: " << vol_file << " will be deleted \n";
65  }
66  else if( argc == 6 )
67  {
68  remove_output = false;
69  filename_bot = argv[1];
70  filename_top = argv[2];
71  polygon_file_name = argv[3];
72  min_dot = atof( argv[4] );
73  vol_file = argv[5];
74  }
75  else
76  {
77  std::cout << " wrong number of arguments\n";
78  return 1; // fail
79  }
80  Core mbcore;
81  Interface* mb = &mbcore;
82 
83  ErrorCode rval = mb->load_file( filename_bot.c_str() );MB_CHK_SET_ERR( rval, "failed to load bed file" );
84 
85  rval = mb->load_file( filename_top.c_str() ); // load the second face (we know we have one face in each file)
86  MB_CHK_SET_ERR( rval, "failed to load top file" );
87 
88  FBEngine* pFacet = new FBEngine( mb, NULL, true ); // smooth facetting, no OBB tree passed
89 
90  if( !pFacet ) return 1; // error
91 
92  // should the init be part of constructor or not?
93  // this is where the obb tree is constructed, and smooth faceting initialized, too.
94  rval = pFacet->Init();MB_CHK_SET_ERR( rval, "failed to initialize smoothing" );
95 
96  std::cout << "volume creation test: ";
97  rval = volume_test( pFacet );
99  std::cout << "\n";
100 
101  if( remove_output )
102  {
103  remove( vol_file.c_str() );
104  }
105  return number_tests_failed;
106 }

References ErrorCode, filename_bot, filename_top, handle_error_code(), moab::FBEngine::Init(), moab::Core::load_file(), mb, MB_CHK_SET_ERR, mbcore, min_dot, number_tests_failed, number_tests_successful, polygon_file_name, vol_file, and volume_test().

◆ volume_test()

ErrorCode volume_test ( FBEngine pFacet)

Definition at line 108 of file crop_vol_test.cpp.

109 {
110  // there should be 2 faces in the model
111  std::ifstream datafile( polygon_file_name.c_str(), std::ifstream::in );
112  if( !datafile )
113  {
114  std::cout << "can't read file\n";
115  return MB_FAILURE;
116  }
117  //
118  char temp[100];
119  double direction[3]; // normalized
120  double gridSize;
121  datafile.getline( temp, 100 ); // first line
122 
123  // get direction and mesh size along polygon segments, from file
124  sscanf( temp, " %lf %lf %lf %lf ", direction, direction + 1, direction + 2, &gridSize );
125  // NORMALIZE(direction);// just to be sure
126 
127  std::vector< double > xyz;
128  while( !datafile.eof() )
129  {
130  datafile.getline( temp, 100 );
131  // int id = 0;
132  double x, y, z;
133  int nr = sscanf( temp, "%lf %lf %lf", &x, &y, &z );
134  if( nr == 3 )
135  {
136  xyz.push_back( x );
137  xyz.push_back( y );
138  xyz.push_back( z );
139  }
140  }
141  int sizePolygon = (int)xyz.size() / 3;
142  if( sizePolygon < 3 )
143  {
144  std::cerr << " Not enough points in the polygon" << std::endl;
145  return MB_FAILURE;
146  }
148  ErrorCode rval = pFacet->getRootSet( &root_set );MB_CHK_SET_ERR( rval, "ERROR : getRootSet failed!" );
149 
150  int top = 2; // iBase_FACE;
151 
152  Range faces;
153  rval = pFacet->getEntities( root_set, top, faces );MB_CHK_SET_ERR( rval, "Failed to get faces in volume_test." );
154 
155  if( 2 != faces.size() )
156  {
157  std::cerr << "expected 2 faces, top and bottom\n";
158  return MB_FAILURE;
159  }
160  EntityHandle newFace1; // first test is with closed surface
161  rval = pFacet->split_surface_with_direction( faces[0], xyz, direction, /*closed*/ 1, min_dot, newFace1 );MB_CHK_SET_ERR( rval, "Failed to crop first face." );
162 
163  EntityHandle newFace2; // first test is with closed surface
164  rval = pFacet->split_surface_with_direction( faces[1], xyz, direction, /*closed*/ 1, min_dot, newFace2 );MB_CHK_SET_ERR( rval, "Failed to crop second face." );
165 
166  // here we make the assumption that the edges, vertices are matching fine...
167  EntityHandle volume;
168  rval = pFacet->create_volume_with_direction( newFace1, newFace2, direction, volume );MB_CHK_SET_ERR( rval, "Failed to create volume." );
169 
170  Interface* mb = pFacet->moab_instance();
171  pFacet->delete_smooth_tags();
172  // duplicate -- extract a new geom topo tool
173  GeomTopoTool* gtt = pFacet->get_gtt();
174  GeomTopoTool* duplicate = NULL;
175  std::vector< EntityHandle > gents;
176  gents.push_back( volume );
177  rval = gtt->duplicate_model( duplicate, &gents );MB_CHK_SET_ERR( rval, "Failed to extract volume." );
178  EntityHandle newRootSet = duplicate->get_root_model_set();
179  delete pFacet;
180  pFacet = NULL; // try not to write the obb tree
181  delete duplicate;
182  rval = mb->write_file( vol_file.c_str(), NULL, NULL, &newRootSet, 1 );
183 
184  return rval;
185 }

References moab::FBEngine::create_volume_with_direction(), moab::FBEngine::delete_smooth_tags(), moab::GeomTopoTool::duplicate_model(), ErrorCode, moab::FBEngine::get_gtt(), moab::GeomTopoTool::get_root_model_set(), moab::FBEngine::getEntities(), moab::FBEngine::getRootSet(), mb, MB_CHK_SET_ERR, min_dot, moab::FBEngine::moab_instance(), nr, polygon_file_name, root_set, moab::Range::size(), moab::FBEngine::split_surface_with_direction(), vol_file, and moab::Core::write_file().

Referenced by main().

Variable Documentation

◆ filename_bot

std::string filename_bot

Definition at line 24 of file crop_vol_test.cpp.

Referenced by main().

◆ filename_top

std::string filename_top

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

Definition at line 23 of file crop_vol_test.cpp.

Referenced by main().

◆ min_dot

◆ number_tests_failed

int number_tests_failed = 0

Definition at line 30 of file crop_vol_test.cpp.

Referenced by main().

◆ number_tests_successful

int number_tests_successful = 0

Definition at line 29 of file crop_vol_test.cpp.

Referenced by main().

◆ polygon_file_name

std::string polygon_file_name

Definition at line 25 of file crop_vol_test.cpp.

Referenced by main(), and volume_test().

◆ vol_file

std::string vol_file

Definition at line 27 of file crop_vol_test.cpp.

Referenced by main(), and volume_test().