static void cmdedit( void ) { double pt[ 3 ], r[ 3 ], c[ 3 ], h, xrot, yrot, rot; int i, j, n, vi, snum; csSetLayer( layer1 ); csMergePoints( 0 ); if ( atom_type == ATYPE_SPHERE ) { mgMonitorBegin( "Sphere Atoms", NULL, seqlen ); csSetLayer( layer1 ); for ( j = 0; j < seqlen; j++ ) { n = atom_count( seq[ j ] ); for ( i = 0; i < n; i++ ) { atom_info( seq[ j ], i, &vi, &snum ); vert_coords( seq[ j ], vi, pt ); transform_point( j * 3.4, j * 36.0, pt ); r[ 0 ] = r[ 1 ] = r[ 2 ] = atom_radius[ snum ]; csSetDefaultSurface( surface_name( snum )); csMakeBall( r, atom_nsides, atom_nsegments, pt ); } if ( userabort = mgMonitorStep( 1 )) break; } mgMonitorDone(); } if ( bond_type == BTYPE_CYLINDER && !userabort ) { mgMonitorBegin( "Cylinder Bonds", NULL, seqlen ); for ( j = 0; j < seqlen; j++ ) { n = bond_count( seq[ j ] ); for ( i = 0; i < n; i++ ) { bond_coords( seq[ j ], i, pt, &h, &xrot, &yrot, &snum ); pt[ 1 ] += 3.4 * j; csSetLayer( layer2 ); csSetDefaultSurface( surface_name( snum )); r[ 0 ] = r[ 1 ] = r[ 2 ] = bond_radius; c[ 0 ] = c[ 2 ] = 0.0; c[ 1 ] = h / 2.0; csMakeDisc( r, h, 0, "Y", bond_nsides, bond_nsegments, c ); csRotate( xrot, "X", NULL ); csRotate( yrot, "Y", NULL ); csMove( pt ); rot = 36 * j; csRotate( rot, "Y", NULL ); csCut(); csSetLayer( layer1 ); csPaste(); } if ( userabort = mgMonitorStep( 1 )) break; } mgMonitorDone(); } }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; TCLAP::CmdLine cmd( "Creates boundary conditions for mesh nodes along polylines." "The documentation is available at https://docs.opengeosys.org/docs/tools/model-preparation/create-boundary-conditions-along-a-polyline", ' ', "0.1"); TCLAP::ValueArg<bool> gml_arg("", "gml", "if switched on write found nodes to file in gml format", false, 0, "bool"); cmd.add(gml_arg); TCLAP::ValueArg<std::string> output_base_fname("o", "output-base-file-name", "the base name of the file the output (geometry (gli) and boundary"\ "condition (bc)) will be written to", true, "", "file name"); cmd.add(output_base_fname); TCLAP::ValueArg<std::string> bc_type("t", "type", "the process type the boundary condition will be written for "\ "currently LIQUID_FLOW (primary variable PRESSURE1) and "\ "GROUNDWATER_FLOW (primary variable HEAD, default) are supported", true, "", "process type as string (LIQUID_FLOW or GROUNDWATER_FLOW (default))"); cmd.add(bc_type); TCLAP::ValueArg<double> search_length_arg("s", "search-length", "The size of the search length. The default value is " "std::numeric_limits<double>::epsilon()", false, std::numeric_limits<double>::epsilon(), "floating point number"); cmd.add(search_length_arg); TCLAP::ValueArg<std::string> geometry_fname("i", "input-geometry", "the name of the file containing the input geometry", true, "", "file name"); cmd.add(geometry_fname); TCLAP::ValueArg<std::string> mesh_arg("m", "mesh-file", "the name of the file containing the mesh", true, "", "file name"); cmd.add(mesh_arg); cmd.parse(argc, argv); // *** read mesh INFO("Reading mesh \"%s\" ... ", mesh_arg.getValue().c_str()); MeshLib::Mesh * subsurface_mesh(FileIO::readMeshFromFile(mesh_arg.getValue())); INFO("done."); INFO("Extracting top surface of mesh \"%s\" ... ", mesh_arg.getValue().c_str()); const MathLib::Vector3 dir(0,0,-1); double const angle(90); std::unique_ptr<MeshLib::Mesh> surface_mesh( MeshLib::MeshSurfaceExtraction::getMeshSurface(*subsurface_mesh, dir, angle)); INFO("done."); delete subsurface_mesh; subsurface_mesh = nullptr; // *** read geometry GeoLib::GEOObjects geometries; FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries); std::string geo_name; { std::vector<std::string> geo_names; geometries.getGeometryNames(geo_names); geo_name = geo_names[0]; } // *** check if the data is usable // *** get vector of polylines std::vector<GeoLib::Polyline*> const* plys(geometries.getPolylineVec(geo_name)); if (!plys) { ERR("Could not get vector of polylines out of geometry \"%s\".", geo_name.c_str()); return -1; } MeshGeoToolsLib::SearchLength search_length_strategy; if (search_length_arg.isSet()) { search_length_strategy = MeshGeoToolsLib::SearchLength(search_length_arg.getValue()); } GeoLib::GEOObjects geometry_sets; MeshGeoToolsLib::MeshNodeSearcher mesh_searcher(*surface_mesh, search_length_strategy); for(std::size_t k(0); k<plys->size(); k++) { std::vector<std::size_t> ids (mesh_searcher.getMeshNodeIDsAlongPolyline(*((*plys)[k]))); if (ids.empty()) continue; std::string geo_name("Polyline-"+std::to_string(k)); convertMeshNodesToGeometry(surface_mesh->getNodes(), ids, geo_name, geometry_sets); } // merge all together std::vector<std::string> geo_names; geometry_sets.getGeometryNames(geo_names); if (geo_names.empty()) { ERR("Did not find mesh nodes along polylines."); return -1; } std::string merge_name("AllMeshNodesAlongPolylines"); if (geometry_sets.mergeGeometries(geo_names, merge_name) == 2) merge_name = geo_names[0]; GeoLib::PointVec const* pnt_vec(geometry_sets.getPointVecObj(merge_name)); std::vector<GeoLib::Point*> const* merged_pnts(pnt_vec->getVector()); std::vector<GeoLib::Point> pnts_with_id; const std::size_t n_merged_pnts(merged_pnts->size()); for(std::size_t k(0); k<n_merged_pnts; ++k) { pnts_with_id.emplace_back(*((*merged_pnts)[k]), k); } std::sort(pnts_with_id.begin(), pnts_with_id.end(), [](GeoLib::Point const& p0, GeoLib::Point const& p1) { return p0 < p1; } ); double const eps (std::numeric_limits<double>::epsilon()); auto surface_pnts = std::unique_ptr<std::vector<GeoLib::Point*>>( new std::vector<GeoLib::Point*>); std::map<std::string, std::size_t> *name_id_map( new std::map<std::string, std::size_t> ); // insert first point surface_pnts->push_back( new GeoLib::Point(pnts_with_id[0], surface_pnts->size())); std::string element_name; pnt_vec->getNameOfElementByID(0, element_name); name_id_map->insert( std::pair<std::string, std::size_t>(element_name,0) ); for (std::size_t k(1); k < n_merged_pnts; ++k) { const GeoLib::Point& p0 (pnts_with_id[k-1]); const GeoLib::Point& p1 (pnts_with_id[k]); if (std::abs (p0[0] - p1[0]) > eps || std::abs (p0[1] - p1[1]) > eps) { surface_pnts->push_back(new GeoLib::Point(pnts_with_id[k], surface_pnts->size())); std::string element_name; pnt_vec->getNameOfElementByID(k, element_name); name_id_map->insert( std::pair<std::string, std::size_t>(element_name, surface_pnts->size()-1) ); } } std::string surface_name(BaseLib::dropFileExtension(mesh_arg.getValue())+"-MeshNodesAlongPolylines"); geometry_sets.addPointVec(std::move(surface_pnts), surface_name, name_id_map, 1e-6); // write the BCs and the merged geometry set to file std::string const base_fname( BaseLib::dropFileExtension(output_base_fname.getValue())); writeBCsAndGeometry(geometry_sets, surface_name, base_fname, bc_type.getValue(), gml_arg.getValue()); return 0; }
static void meshedit( void ) { double pt[ 3 ]; LWPntID id[ 57 ], vid[ 2 ]; int i, j, k, n, v[ 9 ], snum; csMeshBegin( 0, 0, OPSEL_GLOBAL ); if ( bond_type == BTYPE_LINE ) { mgMonitorBegin( "Line Bonds", NULL, seqlen ); for ( j = 0; j < seqlen; j++ ) { n = point_count( seq[ j ] ); for ( i = 0; i < n; i++ ) { vert_coords( seq[ j ], i, pt ); transform_point( j * 3.4, j * 36.0, pt ); id[ i ] = meAddPoint( pt ); } n = bond_count( seq[ j ] ); for ( i = 0; i < n; i++ ) { bond_info( seq[ j ], i, &v[ 0 ], &v[ 1 ], &snum ); vid[ 0 ] = id[ v[ 0 ]]; vid[ 1 ] = id[ v[ 1 ]]; meAddPoly( LWPOLTYPE_FACE, NULL, surface_name( snum ), 2, vid ); } if ( userabort = mgMonitorStep( 1 )) break; } mgMonitorDone(); } if ( atom_type == ATYPE_POINT && !userabort ) { mgMonitorBegin( "Point Atoms", NULL, seqlen ); for ( j = 0; j < seqlen; j++ ) { n = atom_count( seq[ j ] ); for ( i = 0; i < n; i++ ) { atom_info( seq[ j ], i, &v[ 0 ], &snum ); vert_coords( seq[ j ], v[ 0 ], pt ); transform_point( j * 3.4, j * 36.0, pt ); id[ 0 ] = meAddPoint( pt ); meAddPoly( LWPOLTYPE_FACE, NULL, surface_name( snum ), 1, &id[ 0 ] ); } if ( userabort = mgMonitorStep( 1 )) break; } mgMonitorDone(); } else if ( atom_type == ATYPE_DODEC && !userabort ) { mgMonitorBegin( "Dodecahedron Atoms", NULL, seqlen ); for ( j = 0; j < seqlen; j++ ) { n = atom_count( seq[ j ] ); for ( i = 0; i < n; i++ ) { atom_info( seq[ j ], i, &v[ 0 ], &snum ); vert_coords( seq[ j ], v[ 0 ], pt ); transform_point( j * 3.4, j * 36.0, pt ); dodec( pt, atom_radius[ snum ], surface_name( snum )); } if ( userabort = mgMonitorStep( 1 )) break; } mgMonitorDone(); } if ( do_plates && !userabort ) { mgMonitorBegin( "Base Plates", NULL, seqlen ); for ( j = 0; j < seqlen; j++ ) { for ( i = 0; i < 2; i++ ) { plate_info( seq[ j ], i, &n, v, &snum ); for ( k = 0; k < n; k++ ) { vert_coords( seq[ j ], v[ k ], pt ); transform_point( j * 3.4, j * 36.0, pt ); id[ k ] = meAddPoint( pt ); } meAddPoly( LWPOLTYPE_FACE, NULL, surface_name( snum ), n, id ); } if ( userabort = mgMonitorStep( 1 )) break; } mgMonitorDone(); } csMeshDone( EDERR_NONE, 0 ); }