|
| 1 | +/* |
| 2 | + * Copyright (c) 2019 - 2022 Geode-solutions. All rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +#include <absl/flags/flag.h> |
| 6 | +#include <absl/flags/parse.h> |
| 7 | +#include <absl/flags/usage.h> |
| 8 | + |
| 9 | +#include <async++.h> |
| 10 | + |
| 11 | +#include <geode/basic/assert.h> |
| 12 | +#include <geode/basic/filename.h> |
| 13 | +#include <geode/basic/logger.h> |
| 14 | + |
| 15 | +#include <geode/mesh/core/hybrid_solid.h> |
| 16 | +#include <geode/mesh/core/mesh_factory.h> |
| 17 | +#include <geode/mesh/core/polyhedral_solid.h> |
| 18 | +#include <geode/mesh/core/tetrahedral_solid.h> |
| 19 | +#include <geode/mesh/io/hybrid_solid_input.h> |
| 20 | +#include <geode/mesh/io/polyhedral_solid_input.h> |
| 21 | +#include <geode/mesh/io/tetrahedral_solid_input.h> |
| 22 | + |
| 23 | +#include <geode/io/mesh/detail/common.h> |
| 24 | + |
| 25 | +#include <geode/inspector/criterion/colocation/solid_colocation.h> |
| 26 | +#include <geode/inspector/criterion/degeneration/solid_degeneration.h> |
| 27 | + |
| 28 | +ABSL_FLAG( std::string, input, "/path/my/solid.og_tso3d", "Input solid" ); |
| 29 | +ABSL_FLAG( bool, colocation, true, "Toggle colocation criterion" ); |
| 30 | +ABSL_FLAG( bool, degeneration, true, "Toggle degeneration criterion" ); |
| 31 | + |
| 32 | +template < geode::index_t dimension > |
| 33 | +void inspect_solid( const geode::SolidMesh< dimension >& solid ) |
| 34 | +{ |
| 35 | + absl::InlinedVector< async::task< void >, 2 > tasks; |
| 36 | + if( absl::GetFlag( FLAGS_colocation ) ) |
| 37 | + { |
| 38 | + tasks.emplace_back( async::spawn( [&solid] { |
| 39 | + const geode::SolidMeshColocation< dimension > colocation{ solid }; |
| 40 | + const auto nb = colocation.nb_colocated_points(); |
| 41 | + geode::Logger::info( nb, " colocated points" ); |
| 42 | + } ) ); |
| 43 | + } |
| 44 | + if( absl::GetFlag( FLAGS_degeneration ) ) |
| 45 | + { |
| 46 | + tasks.emplace_back( async::spawn( [&solid] { |
| 47 | + const geode::SolidMeshDegeneration< dimension > degeneration{ |
| 48 | + solid |
| 49 | + }; |
| 50 | + const auto nb = degeneration.nb_degenerated_edges(); |
| 51 | + geode::Logger::info( nb, " degenerated edges" ); |
| 52 | + } ) ); |
| 53 | + } |
| 54 | + async::when_all( tasks.begin(), tasks.end() ).wait(); |
| 55 | +} |
| 56 | + |
| 57 | +int main( int argc, char* argv[] ) |
| 58 | +{ |
| 59 | + try |
| 60 | + { |
| 61 | + absl::SetProgramUsageMessage( |
| 62 | + absl::StrCat( "Solid inspector from Geode-solutions.\n", |
| 63 | + "Sample usage:\n", argv[0], " --input my_solid.og_tsf3d\n", |
| 64 | + "Default behavior test all available criteria, to disable one " |
| 65 | + "use --noXXX, e.g. --noadjacency" ) ); |
| 66 | + absl::ParseCommandLine( argc, argv ); |
| 67 | + |
| 68 | + geode::detail::initialize_mesh_io(); |
| 69 | + const auto filename = absl::GetFlag( FLAGS_input ); |
| 70 | + const auto ext = |
| 71 | + geode::to_string( geode::extension_from_filename( filename ) ); |
| 72 | + |
| 73 | + if( geode::TetrahedralSolidInputFactory3D::has_creator( ext ) ) |
| 74 | + { |
| 75 | + inspect_solid( *geode::load_tetrahedral_solid< 3 >( filename ) ); |
| 76 | + } |
| 77 | + else if( geode::PolyhedralSolidInputFactory3D::has_creator( ext ) ) |
| 78 | + { |
| 79 | + inspect_solid( *geode::load_polyhedral_solid< 3 >( filename ) ); |
| 80 | + } |
| 81 | + else if( geode::HybridSolidInputFactory3D::has_creator( ext ) ) |
| 82 | + { |
| 83 | + inspect_solid( *geode::load_hybrid_solid< 3 >( filename ) ); |
| 84 | + } |
| 85 | + else |
| 86 | + { |
| 87 | + throw geode::OpenGeodeException( "Unable to load file ", filename ); |
| 88 | + } |
| 89 | + |
| 90 | + return 0; |
| 91 | + } |
| 92 | + catch( ... ) |
| 93 | + { |
| 94 | + return geode::geode_lippincott(); |
| 95 | + } |
| 96 | +} |
0 commit comments