Reintroduce --center-model and --center-model-geometry

This commit is contained in:
Thomas Krijnen
2024-11-29 13:03:56 +01:00
parent 8edbb37121
commit 4ec8ceb134
3 changed files with 42 additions and 74 deletions
+28 -58
View File
@@ -449,8 +449,6 @@ int main(int argc, char** argv) {
const bool center_model = vmap.count("center-model") != 0;
const bool center_model_geometry = vmap.count("center-model-geometry") != 0;
const bool model_offset = vmap.count("model-offset") != 0;
const bool model_rotation = vmap.count("model-rotation") != 0;
if (!quiet || vmap.count("version")) {
print_version();
@@ -894,7 +892,7 @@ int main(int argc, char** argv) {
if (geometry_settings.get<ifcopenshell::geometry::settings::GenerateUvs>().get()) {
Logger::Notice("Generate UVs setting ignored when writing non-tesselated output");
}
if (center_model || center_model_geometry || model_offset) {
if (center_model || center_model_geometry) {
Logger::Notice("Centering/offsetting model setting ignored when writing non-tesselated output");
}
@@ -922,72 +920,44 @@ int main(int argc, char** argv) {
} else {
Logger::SetOutput(quiet ? nullptr : &cout_, vcounter.count > 1 ? &cout_ : &log_stream);
}
/*
// @todo
if (model_rotation) {
std::array<double, 4> &rotation = settings.rotation;
if (sscanf(rotation_str.c_str(), "%lf;%lf;%lf;%lf", &rotation[0], &rotation[1], &rotation[2], &rotation[3]) != 4) {
cerr_ << "[Error] Invalid use of --model-rotation\n";
IfcUtil::path::delete_file(IfcUtil::path::to_utf8(output_temp_filename));
print_options(serializer_options);
return EXIT_FAILURE;
}
std::stringstream msg;
msg << "Using model rotation (" << rotation[0] << "," << rotation[1] << "," << rotation[2] << "," << rotation[3] << ")";
Logger::Notice(msg.str());
}
if (is_tesselated && (center_model || center_model_geometry || model_offset)) {
std::array<double, 3> &offset = settings.offset;
if (center_model || center_model_geometry) {
if (site_local_placement || building_local_placement) {
Logger::Error("Cannot use --center-model or --center-model-geometry together with --{site,building}-local-placement");
if (is_tesselated && (center_model || center_model_geometry)) {
std::vector<double> offset(3);
IfcGeom::Iterator tmp_context_iterator(geometry_kernel, geometry_settings, ifc_file, filter_funcs, num_threads);
time_t start, end;
time(&start);
if (!quiet) Logger::Status("Computing bounds...");
if (center_model_geometry) {
if (!tmp_context_iterator.initialize()) {
/// @todo It would be nice to know and print separate error prints for a case where we found no entities
/// and for a case we found no entities that satisfy our filtering criteria.
Logger::Notice("No geometrical elements found or none successfully converted");
serializer.reset();
IfcUtil::path::delete_file(IfcUtil::path::to_utf8(output_temp_filename));
write_log(!quiet);
return EXIT_FAILURE;
}
IfcGeom::Iterator tmp_context_iterator(geometry_kernel, settings, ifc_file, filter_funcs, num_threads);
time_t start, end;
time(&start);
if (!quiet) Logger::Status("Computing bounds...");
if (center_model_geometry) {
if (!tmp_context_iterator.initialize()) {
/// @todo It would be nice to know and print separate error prints for a case where we found no entities
/// and for a case we found no entities that satisfy our filtering criteria.
Logger::Notice("No geometrical elements found or none successfully converted");
serializer.reset();
IfcUtil::path::delete_file(IfcUtil::path::to_utf8(output_temp_filename));
write_log(!quiet);
return EXIT_FAILURE;
}
}
}
tmp_context_iterator.compute_bounds(center_model_geometry);
tmp_context_iterator.compute_bounds(center_model_geometry);
time(&end);
if (!quiet) Logger::Status("Done ! Bounds computed in " + format_duration(start, end));
time(&end);
if (!quiet) Logger::Status("Done ! Bounds computed in " + format_duration(start, end));
auto center = (tmp_context_iterator.bounds_min().ccomponents() + tmp_context_iterator.bounds_max().ccomponents()) * 0.5;
offset[0] = -center(0);
offset[1] = -center(1);
offset[2] = -center(2);
} else {
if (sscanf(offset_str.c_str(), "%lf;%lf;%lf", &offset[0], &offset[1], &offset[2]) != 3) {
cerr_ << "[Error] Invalid use of --model-offset\n";
IfcUtil::path::delete_file(IfcUtil::path::to_utf8(output_temp_filename));
print_options(serializer_options);
return EXIT_FAILURE;
}
}
auto center = (tmp_context_iterator.bounds_min().ccomponents() + tmp_context_iterator.bounds_max().ccomponents()) * 0.5;
offset[0] = -center(0);
offset[1] = -center(1);
offset[2] = -center(2);
std::stringstream msg;
msg << std::setprecision (std::numeric_limits< double >::max_digits10) << "Using model offset (" << offset[0] << "," << offset[1] << "," << offset[2] << ")";
Logger::Notice(msg.str());
geometry_settings.get<ifcopenshell::geometry::settings::ModelOffset>().value = offset;
}
*/
// backwards compatibility
if (vmap.count("plan") && vmap.count("model")) {
+8 -15
View File
@@ -127,14 +127,12 @@ namespace IfcGeom {
// ?
size_t async_elements_returned_ = 0;
size_t task_result_index_ = 0;
std::string geometry_library_;
ifcopenshell::geometry::Settings settings_;
IfcParse::IfcFile* ifc_file;
std::vector<filter_t> filters_;
bool owns_ifc_file;
int num_threads_;
std::string geometry_library_;
// When single-threaded
ifcopenshell::geometry::Converter* converter_;
@@ -195,7 +193,6 @@ namespace IfcGeom {
}
time_points[0] = high_resolution_clock::now();
converter_ = new ifcopenshell::geometry::Converter(geometry_library_, ifc_file, settings_);
std::vector<ifcopenshell::geometry::geometry_conversion_task> reps;
if (num_threads_ != 1) {
// @todo this shouldn't be necessary with properly immutable taxonomy items
@@ -420,7 +417,7 @@ namespace IfcGeom {
for (int i = 0; i < 3; ++i) {
bounds_min_.components()(i) = std::min(bounds_min_.components()(i), transformed(i));
bounds_max_.components()(i) = std::max(bounds_min_.components()(i), transformed(i));
bounds_max_.components()(i) = std::max(bounds_max_.components()(i), transformed(i));
}
}
} while (++num_created, next());
@@ -439,7 +436,7 @@ namespace IfcGeom {
for (int i = 0; i < 3; ++i) {
bounds_min_.components()(i) = std::min(bounds_min_.components()(i), vec(i));
bounds_max_.components()(i) = std::max(bounds_min_.components()(i), vec(i));
bounds_max_.components()(i) = std::max(bounds_max_.components()(i), vec(i));
}
}
}
@@ -838,9 +835,9 @@ namespace IfcGeom {
: settings_(settings)
, ifc_file(file)
, filters_(filters)
, owns_ifc_file(false)
, num_threads_(num_threads)
, geometry_library_(geometry_library)
, converter_(new ifcopenshell::geometry::Converter(geometry_library_, ifc_file, settings_))
{
}
@@ -848,36 +845,36 @@ namespace IfcGeom {
: settings_(settings)
, ifc_file(file)
, filters_(filters)
, owns_ifc_file(false)
, num_threads_(num_threads)
, geometry_library_("opencascade")
, converter_(new ifcopenshell::geometry::Converter(geometry_library_, ifc_file, settings_))
{
}
Iterator(const ifcopenshell::geometry::Settings& settings, IfcParse::IfcFile* file)
: settings_(settings)
, ifc_file(file)
, owns_ifc_file(false)
, num_threads_(1)
, geometry_library_("opencascade")
, converter_(new ifcopenshell::geometry::Converter(geometry_library_, ifc_file, settings_))
{
}
Iterator(const std::string& geometry_library, const ifcopenshell::geometry::Settings& settings, IfcParse::IfcFile* file)
: settings_(settings)
, ifc_file(file)
, owns_ifc_file(false)
, num_threads_(1)
, geometry_library_(geometry_library)
, converter_(new ifcopenshell::geometry::Converter(geometry_library_, ifc_file, settings_))
{
}
Iterator(const std::string& geometry_library, const ifcopenshell::geometry::Settings& settings, IfcParse::IfcFile* file, int num_threads)
: settings_(settings)
, ifc_file(file)
, owns_ifc_file(false)
, num_threads_(num_threads)
, geometry_library_(geometry_library)
, converter_(new ifcopenshell::geometry::Converter(geometry_library_, ifc_file, settings_))
{
}
@@ -890,10 +887,6 @@ namespace IfcGeom {
}
}
if (owns_ifc_file) {
delete ifc_file;
}
if (!settings_.get<ifcopenshell::geometry::settings::IteratorOutput>().get() == ifcopenshell::geometry::settings::NATIVE) {
for (auto& p : all_processed_native_elements_) {
delete p;
+6 -1
View File
@@ -79,7 +79,12 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcObjectPlacement* inst) {
} else {
// The parent placement of the current is a placement for a type that is
// being ignored (Site or Building) or it is the host element of an opening.
result = taxonomy::cast<taxonomy::matrix4>(map(transform));
// Create a new copy around `result` so that it's cached copy is not altered
// @todo immutability
result = taxonomy::make<taxonomy::matrix4>(
taxonomy::cast<taxonomy::matrix4>(map(transform))->ccomponents()
);
}
if (fallback) {