Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen shot maker #446

Merged
merged 23 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ if(NOT eigen_POPULATED)
endif()


FetchContent_Declare(
tclap
GIT_REPOSITORY https://github.com/mirror/tclap.git
GIT_TAG v1.2.2
)

FetchContent_GetProperties(tclap)
if(NOT tclap_POPULATED)
FetchContent_Populate(tclap)
endif()


FetchContent_Declare(
visit_struct
GIT_REPOSITORY https://github.com/cbeck88/visit_struct.git
Expand Down
2 changes: 1 addition & 1 deletion Core/src/IfcGeometryConverter/IfcImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ OIP_NAMESPACE_OPENINFRAPLATFORM_CORE_IFCGEOMETRYCONVERTER_BEGIN
template <
class IfcEntityTypesT
>
IfcImporterT<IfcEntityTypesT>::IfcImporterT<IfcEntityTypesT>()
IfcImporterT<IfcEntityTypesT>::IfcImporterT<IfcEntityTypesT>::IfcImporterT()
{
geomSettings = std::make_shared<GeometrySettings>();
unitConverter = std::make_shared<UnitConverter<IfcEntityTypesT>>();
Expand Down
13 changes: 0 additions & 13 deletions ExpressBindingGenerator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ find_package(FLEX REQUIRED)
find_package(BISON REQUIRED)


#find_path(TCLAP_INCLUDE_DIR REQUIRED)
FetchContent_Declare(
tclap
GIT_REPOSITORY https://github.com/mirror/tclap.git
GIT_TAG v1.2.2
)

FetchContent_GetProperties(tclap)
if(NOT tclap_POPULATED)
FetchContent_Populate(tclap)
endif()


# Macro to add IFC formats and the respective schemas.
macro(add_format format schema active)
set(${format}_SCHEMA ${schema}.exp)
Expand Down
3 changes: 2 additions & 1 deletion UnitTests/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

add_subdirectory(GeometryModelRenderer)
add_subdirectory(GeometryModelRenderer)
add_subdirectory(ScreenShotMaker)
10 changes: 5 additions & 5 deletions UnitTests/Utilities/GeometryModelRenderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

project(GeometryModelRenderer)
project(OpenInfraPlatform.GeometryModelRenderer)

set(CMAKE_AUTOMOC OFF)

file(GLOB OpenInfraPlatform_UnitTests_Utilities_GeometryModelRenderer_Source src/*.*)

source_group(src FILES ${OpenInfraPlatform_UnitTests_Utilities_GeometryModelRenderer_Source})

add_library(GeometryModelRenderer STATIC ${OpenInfraPlatform_UnitTests_Utilities_GeometryModelRenderer_Source})
add_library(OpenInfraPlatform.GeometryModelRenderer STATIC ${OpenInfraPlatform_UnitTests_Utilities_GeometryModelRenderer_Source})


target_include_directories(GeometryModelRenderer
target_include_directories(OpenInfraPlatform.GeometryModelRenderer
PUBLIC
src
)

target_link_libraries(GeometryModelRenderer
target_link_libraries(OpenInfraPlatform.GeometryModelRenderer
PRIVATE
OpenInfraPlatform.Rendering
BlueFramework.Engine
Expand All @@ -41,4 +41,4 @@ target_link_libraries(GeometryModelRenderer
Boost::filesystem
)

set_target_properties(GeometryModelRenderer PROPERTIES FOLDER "OpenInfraPlatform/UnitTests/Utilities")
set_target_properties(OpenInfraPlatform.GeometryModelRenderer PROPERTIES FOLDER "OpenInfraPlatform/UnitTests/Utilities")
51 changes: 51 additions & 0 deletions UnitTests/Utilities/ScreenShotMaker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Copyright (c) 2021 Technical University of Munich
# Chair of Computational Modeling and Simulation.
#
# TUM Open Infra Platform is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 3
# as published by the Free Software Foundation.
#
# TUM Open Infra Platform is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

project(OpenInfraPlatform.ScreenShotMaker)

set(CMAKE_AUTOMOC OFF)

file(GLOB OpenInfraPlatform_UnitTests_Utilities_ScreenShotMaker_Source src/*.*)

source_group(src FILES ${OpenInfraPlatform_UnitTests_Utilities_ScreenShotMaker_Source})

add_executable(OpenInfraPlatform.ScreenShotMaker ${OpenInfraPlatform_UnitTests_Utilities_ScreenShotMaker_Source})

get_directory_property(PARENT_DIR DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PARENT_DIRECTORY)

target_include_directories(OpenInfraPlatform.ScreenShotMaker
PUBLIC
src
${tclap_SOURCE_DIR}/include
PRIVATE
${PARENT_DIR}
)

target_link_libraries(OpenInfraPlatform.ScreenShotMaker
PRIVATE
OpenInfraPlatform.GeometryModelRenderer
OpenInfraPlatform.Rendering
BlueFramework.Engine
Boost::filesystem
)

foreach(format ${IFC_FORMATS})
target_link_libraries(OpenInfraPlatform.ScreenShotMaker PRIVATE OpenInfraPlatform.${format})
endforeach()


set_target_properties(OpenInfraPlatform.ScreenShotMaker PROPERTIES FOLDER "OpenInfraPlatform/UnitTests/Utilities")
239 changes: 239 additions & 0 deletions UnitTests/Utilities/ScreenShotMaker/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
This file is part of TUM Open Infra Platform Early Binding EXPRESS
Generator, a simple early binding generator for EXPRESS.
Copyright (c) 2021 Technical University of Munich
Chair of Computational Modeling and Simulation.

TUM Open Infra Platform Early Binding EXPRESS Generator is free
software; you can redistribute it and/or modify it under the terms
of the GNU General Public License Version 3 as published by the Free
Software Foundation.

TUM Open Infra Platform Early Binding EXPRESS Generator is
distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* INSTRUCTIONS

Usage:

> OpenInfraPlatform.ScreenShotMaker.exe <pathToIfcFile> -o <pathToOutputDirectory>

with:

- <pathToIfcFile>: the relative or absolute path to the IFC file to be rendered
- <pathToOutputDirectory>: the relative or absolute path to the directory where screen shots should be saved

*NOTE:* make sure that the correct IFC version is being compiled - select accordingly in CMake.

If you wish to debug, you should put the arguments in [Visual Studio]:
- OpenInfraPlatform.ScreenShotMaker project -> right mouse button
- Properties
- Debuggin
- Command Arguments

*/


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <string>
#include <iostream>
#include <vector>
#include <utility>

#include <boost/filesystem.hpp>

#include "tclap/CmdLine.h"

#include <buw.Engine.h>
#include <buw.ImageProcessing.h>

#include "IfcGeometryConverter\IfcPeekStepReader.h"
using OpenInfraPlatform::Core::IfcGeometryConverter::IfcPeekStepReader;

#include <IfcGeometryConverter/ConverterBuw.h>
#include <IfcGeometryConverter/IfcImporter.h>
#include <IfcGeometryConverter/IfcImporterImpl.h>

#include <IfcGeometryModelRenderer.h>

#ifdef OIP_MODULE_EARLYBINDING_IFC4X1
#include "EarlyBinding\IFC4X1\src\IFC4X1Entities.h"
#include "EarlyBinding\IFC4X1\src\EMTIFC4X1EntityTypes.h"
#endif

#ifdef OIP_MODULE_EARLYBINDING_IFC4X3_RC1
#include "EarlyBinding\IFC4X3_RC1\src\IFC4X3_RC1Entities.h"
#include "EarlyBinding\IFC4X3_RC1\src\EMTIFC4X3_RC1EntityTypes.h"
#endif

#ifdef OIP_MODULE_EARLYBINDING_IFC4X3_RC3
#include <EarlyBinding/IFC4X3_RC3/src/reader/IFC4X3_RC3Reader.h>
#include <EarlyBinding/IFC4X3_RC3/src/IFC4X3_RC3.h>
#endif


template <typename IfcEntityTypesT, class IfcReaderT>
buw::ReferenceCounted<IfcGeometryModelRenderer> setUpRenderer(
const std::string& filename
)
{
// https://docs.microsoft.com/de-de/windows/console/getconsolewindow
HWND handle = GetConsoleWindow();

buw::renderSystemDescription scd;
scd.width = 640;
scd.height = 480;
scd.windowId = static_cast<void*>(handle);
scd.forceWarpDevice = false;
scd.enableMSAA = true;
scd.renderAPI = BlueFramework::Rasterizer::eRenderAPI::Direct3D11;

auto renderSystem_ = BlueFramework::Rasterizer::createRenderSystem(scd);

auto rendererIfc = buw::makeReferenceCounted<IfcGeometryModelRenderer>(renderSystem_);

auto express_model = IfcReaderT::FromFile(filename);

auto importer = buw::makeReferenceCounted<oip::IfcImporterT<IfcEntityTypesT>>();
auto model = importer->collectData(express_model);

rendererIfc->setModel(model[0]);

return rendererIfc;
}


void saveAllViews(
const buw::ReferenceCounted<IfcGeometryModelRenderer>& renderer,
const std::string& outputDirectoryName,
const std::string& filename
)
{
std::vector<std::pair< buw::eViewDirection, std::string >> views =
{
{ buw::eViewDirection::Front, "front"},
{ buw::eViewDirection::Top, "top"},
{ buw::eViewDirection::Bottom, "bottom"},
{ buw::eViewDirection::Left, "left"},
{ buw::eViewDirection::Right, "right"},
{ buw::eViewDirection::Back, "back"},
{ buw::eViewDirection::FrontLeftBottom, "front_left_bottom" },
{ buw::eViewDirection::FrontRightBottom, "front_right_bottom" },
{ buw::eViewDirection::TopLeftFront, "top_left_front" },
{ buw::eViewDirection::TopFrontRight, "top_front_right" },
{ buw::eViewDirection::TopLeftBack, "top_left_back" },
{ buw::eViewDirection::TopRightBack, "top_right_back" },
{ buw::eViewDirection::BackLeftBottom, "back_left_bottom" },
{ buw::eViewDirection::RightBottomBack, "right_bottom_back" }
};

for( const auto& view : views )
{
renderer->setViewDirection( view.first );
buw::Image4b image = renderer->captureImage();
buw::storeImage(outputDirectoryName + "\\" + filename + "_" + view.second + ".png", image);

std::cout << "Saved image " << std::endl;
std::cout << outputDirectoryName + "\\" + filename + "_" + view.second + ".png" << std::endl;
}
}


int main(int argc, char **argv) {
try {
TCLAP::CmdLine cmd("oipScreenShot", ' ', "0.1");

TCLAP::UnlabeledValueArg<std::string> sourceFiles("i", "IFC file.", true, "./rectified", "string");
cmd.add(sourceFiles);

TCLAP::ValueArg<std::string> outputDirectory("o", "outputDir", "The output directory for figures.", true, "", "string");
cmd.add(outputDirectory);

// Parse the args.
cmd.parse(argc, argv);

// open a file handle to a particular file:

const char* filepath = sourceFiles.getValue().c_str();
std::string outputDirectoryName = outputDirectory.getValue();

// check input
boost::filesystem::path givenPathToFile(filepath);
if (!boost::filesystem::exists(givenPathToFile))
throw std::exception("Provided IFC file does not exist.");
if (!boost::filesystem::exists(outputDirectoryName))
throw std::exception("Provided output directory does not exist.");

std::cout << "Generating screen shots from " << std::endl;
std::cout << filepath << std::endl;
std::cout << "Saving screen shots to " << std::endl;
std::cout << outputDirectoryName << std::endl;

std::string filename = givenPathToFile.stem().string();
std::string filetype = givenPathToFile.extension().string();
std::transform(filetype.begin(), filetype.end(), filetype.begin(), ::tolower);

IfcPeekStepReader::IfcSchema ifcSchema;
std::string strSchema;
if (filetype == ".ifc" || filetype == ".stp")
{
std::tie(strSchema, ifcSchema) = IfcPeekStepReader::parseIfcHeader(filepath);
}
else
{
std::string msg("File type not IFC, but " + filetype);
throw std::exception(msg.c_str());
}

buw::ReferenceCounted<IfcGeometryModelRenderer> renderer;
if (ifcSchema == IfcPeekStepReader::IfcSchema::IFC4X1) {
#ifdef OIP_MODULE_EARLYBINDING_IFC4X1
renderer =
setUpRenderer<emt::IFC4X1EntityTypes, OpenInfraPlatform::IFC4X1::IFC4X1Reader>(filepath);
#else // OIP_MODULE_EARLYBINDING_IFC4X1
throw std::exception("IFC4X1 not compiled");
#endif //OIP_MODULE_EARLYBINDING_IFC4X1
}
else if (ifcSchema == IfcPeekStepReader::IfcSchema::IFC4X3_RC1) {
#ifdef OIP_MODULE_EARLYBINDING_IFC4X3_RC1
renderer =
setUpRenderer<emt::IFC4X3_RC1EntityTypes, OpenInfraPlatform::IFC4X3_RC1::IFC4X3_RC1Reader>(filepath);
#else // OIP_MODULE_EARLYBINDING_IFC4X3_RC1
throw std::exception("IFC4X3_RC1 not compiled");
#endif //OIP_MODULE_EARLYBINDING_IFC4X3_RC1
}
else if (ifcSchema == IfcPeekStepReader::IfcSchema::IFC4X3_RC3) {
#ifdef OIP_MODULE_EARLYBINDING_IFC4X3_RC3
renderer =
setUpRenderer<emt::IFC4X3_RC3EntityTypes, OpenInfraPlatform::IFC4X3_RC3::IFC4X3_RC3Reader>(filepath);
#else // OIP_MODULE_EARLYBINDING_IFC4X3_RC3
throw std::exception("IFC4X3_RC3 not compiled");
#endif //OIP_MODULE_EARLYBINDING_IFC4X3_RC3
}
else
{
std::string msg("IFC version " + strSchema + " not supported");
throw std::exception(msg.c_str());
}

saveAllViews(renderer, outputDirectoryName, filename);

} catch (std::exception &ex) {
std::cout << std::endl;
std::cout << "---- EXCEPTION ENCOUNTERED ----" << std::endl;
std::cout << ex.what() << std::endl;
std::cout << "---- Press ENTER to exit ----" << std::endl;
getchar();
}

}
4 changes: 2 additions & 2 deletions cmake/CreateUnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function(CreateIfcFileVisualUnitTestForSchema test_name schema)
PUBLIC
OpenInfraPlatform.${schema}
OpenInfraPlatform.Rendering
GeometryModelRenderer
OpenInfraPlatform.GeometryModelRenderer
BlueFramework.Engine
gmock
gtest
Expand Down Expand Up @@ -98,7 +98,7 @@ function(CreateOffFileVisualUnitTest test_name)
target_link_libraries(${UnitTest_Executable_Name}
PUBLIC
OpenInfraPlatform.Rendering
GeometryModelRenderer
OpenInfraPlatform.GeometryModelRenderer
BlueFramework.Engine
gmock
gtest
Expand Down