From a1a9e214eb74abc893bfab21c8e52c96afd0a569 Mon Sep 17 00:00:00 2001 From: Soeren Peters <peters@irmb.tu-bs.de> Date: Tue, 20 Oct 2020 10:03:40 +0200 Subject: [PATCH] In clang-format: always break after template declarations. apply clang format to /basics --- .clang-format | 2 +- src/basics/Core/ArrayTypes.h | 104 +- src/basics/Core/DataTypes.h | 3 +- src/basics/Core/Input/ConfigData/ConfigData.h | 340 +- .../Core/Input/ConfigData/ConfigDataImp.cpp | 1313 +++----- .../Core/Input/ConfigData/ConfigDataImp.h | 850 +++-- .../ConfigFileReader/ConfigFileReader.cpp | 418 ++- .../Input/ConfigFileReader/ConfigFileReader.h | 4 +- .../Core/Input/ConfigInput/ConfigInput.cpp | 379 +-- .../Core/Input/ConfigInput/ConfigInput.h | 74 +- src/basics/Core/Input/Input.cpp | 13 +- src/basics/Core/Input/Input.h | 23 +- src/basics/Core/Input/JsonInput/JsonInput.cpp | 93 +- src/basics/Core/Input/JsonInput/JsonInput.h | 26 +- src/basics/Core/LbmOrGks.h | 44 +- src/basics/Core/Logger/Logger.cpp | 91 +- src/basics/Core/Logger/Logger.h | 82 +- .../Core/Logger/implementations/LoggerImp.cpp | 68 +- .../Core/Logger/implementations/LoggerImp.h | 59 +- .../Logger/implementations/LoggerTest.cpp | 15 +- src/basics/Core/NonCreatable.h | 14 +- src/basics/Core/RealConstants.h | 420 ++- .../Core/StringUtilities/StringUtil.cpp | 126 +- src/basics/Core/StringUtilities/StringUtil.h | 46 +- .../Core/StringUtilities/StringUtilTest.cpp | 28 +- src/basics/Core/Timer/Timer.h | 5 +- src/basics/Core/Timer/TimerImp.cpp | 18 +- src/basics/Core/Timer/TimerImp.h | 3 - src/basics/Core/VectorTypes.cpp | 20 +- src/basics/Core/VectorTypes.h | 18 +- src/basics/Core/buildInfo.h | 33 +- src/basics/Core/buildInfo.in.cpp | 17 +- src/basics/PointerDefinitions.h | 9 +- src/basics/basics/container/CbArray2D.h | 630 ++-- src/basics/basics/container/CbArray3D.h | 748 ++--- src/basics/basics/container/CbArray4D.h | 752 +++-- src/basics/basics/container/CbVector.h | 454 +-- src/basics/basics/objects/ObObject.h | 54 +- src/basics/basics/utilities/UbComparators.h | 416 ++- src/basics/basics/utilities/UbEqual.h | 316 +- src/basics/basics/utilities/UbException.h | 230 +- src/basics/basics/utilities/UbInfinity.h | 232 +- src/basics/basics/utilities/UbKeys.h | 512 +-- src/basics/basics/utilities/UbLimits.h | 199 +- src/basics/basics/utilities/UbLogger.cpp | 39 +- src/basics/basics/utilities/UbLogger.h | 388 +-- src/basics/basics/utilities/UbMath.cpp | 43 +- src/basics/basics/utilities/UbMath.h | 944 +++--- src/basics/basics/utilities/UbObservable.h | 308 +- src/basics/basics/utilities/UbObserver.h | 78 +- src/basics/basics/utilities/UbScheduler.h | 551 +-- src/basics/basics/utilities/UbSystem.h | 985 +++--- src/basics/basics/utilities/UbTiming.h | 638 ++-- src/basics/basics/utilities/UbTuple.h | 631 ++-- src/basics/basics/utilities/Vector3D.cpp | 869 +++-- src/basics/basics/utilities/Vector3D.h | 234 +- src/basics/basics/writer/WbWriter.h | 216 +- .../basics/writer/WbWriterVtkXmlASCII.cpp | 2220 ++++++------ .../basics/writer/WbWriterVtkXmlASCII.h | 216 +- .../basics/writer/WbWriterVtkXmlBinary.cpp | 2962 +++++++++-------- .../basics/writer/WbWriterVtkXmlBinary.h | 210 +- .../geometry3d/CoordinateTransformation3D.cpp | 343 +- .../geometry3d/CoordinateTransformation3D.h | 173 +- src/basics/geometry3d/GbCuboid3D.cpp | 874 +++-- src/basics/geometry3d/GbCuboid3D.h | 222 +- src/basics/geometry3d/GbLine3D.cpp | 355 +- src/basics/geometry3d/GbLine3D.h | 212 +- src/basics/geometry3d/GbObject3D.cpp | 140 +- src/basics/geometry3d/GbObject3D.h | 255 +- src/basics/geometry3d/GbPoint3D.cpp | 194 +- src/basics/geometry3d/GbPoint3D.h | 172 +- src/basics/geometry3d/GbPolygon3D.cpp | 473 +-- src/basics/geometry3d/GbPolygon3D.h | 466 ++- src/basics/geometry3d/GbSystem3D.cpp | 1533 +++++---- src/basics/geometry3d/GbSystem3D.h | 757 +++-- src/basics/geometry3d/GbTriangle3D.cpp | 1788 +++++----- src/basics/geometry3d/GbTriangle3D.h | 357 +- src/basics/geometry3d/GbVector3D.cpp | 902 +++-- src/basics/geometry3d/GbVector3D.h | 144 +- 79 files changed, 14878 insertions(+), 15315 deletions(-) diff --git a/.clang-format b/.clang-format index 8c4f5d000..1bdc80ff8 100644 --- a/.clang-format +++ b/.clang-format @@ -21,7 +21,7 @@ AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine +AlwaysBreakTemplateDeclarations: Yes BinPackArguments: true BinPackParameters: true BraceWrapping: diff --git a/src/basics/Core/ArrayTypes.h b/src/basics/Core/ArrayTypes.h index 2e50298ce..7d5d70374 100644 --- a/src/basics/Core/ArrayTypes.h +++ b/src/basics/Core/ArrayTypes.h @@ -5,58 +5,58 @@ #include "DataTypes.h" -typedef std::array< uint, 2 > uint_2 ; -typedef std::array< uint, 3 > uint_3 ; -typedef std::array< uint, 4 > uint_4 ; -typedef std::array< uint, 5 > uint_5 ; -typedef std::array< uint, 6 > uint_6 ; -typedef std::array< uint, 7 > uint_7 ; -typedef std::array< uint, 8 > uint_8 ; -typedef std::array< uint, 9 > uint_9 ; -typedef std::array< uint, 10 > uint_10; -typedef std::array< uint, 11 > uint_11; -typedef std::array< uint, 12 > uint_12; -typedef std::array< uint, 13 > uint_13; -typedef std::array< uint, 14 > uint_14; -typedef std::array< uint, 15 > uint_15; -typedef std::array< uint, 16 > uint_16; -typedef std::array< uint, 17 > uint_17; -typedef std::array< uint, 18 > uint_18; -typedef std::array< uint, 19 > uint_19; -typedef std::array< uint, 20 > uint_20; -typedef std::array< uint, 21 > uint_21; -typedef std::array< uint, 22 > uint_22; -typedef std::array< uint, 23 > uint_23; -typedef std::array< uint, 24 > uint_24; -typedef std::array< uint, 25 > uint_25; -typedef std::array< uint, 26 > uint_26; -typedef std::array< uint, 27 > uint_27; +typedef std::array<uint, 2> uint_2; +typedef std::array<uint, 3> uint_3; +typedef std::array<uint, 4> uint_4; +typedef std::array<uint, 5> uint_5; +typedef std::array<uint, 6> uint_6; +typedef std::array<uint, 7> uint_7; +typedef std::array<uint, 8> uint_8; +typedef std::array<uint, 9> uint_9; +typedef std::array<uint, 10> uint_10; +typedef std::array<uint, 11> uint_11; +typedef std::array<uint, 12> uint_12; +typedef std::array<uint, 13> uint_13; +typedef std::array<uint, 14> uint_14; +typedef std::array<uint, 15> uint_15; +typedef std::array<uint, 16> uint_16; +typedef std::array<uint, 17> uint_17; +typedef std::array<uint, 18> uint_18; +typedef std::array<uint, 19> uint_19; +typedef std::array<uint, 20> uint_20; +typedef std::array<uint, 21> uint_21; +typedef std::array<uint, 22> uint_22; +typedef std::array<uint, 23> uint_23; +typedef std::array<uint, 24> uint_24; +typedef std::array<uint, 25> uint_25; +typedef std::array<uint, 26> uint_26; +typedef std::array<uint, 27> uint_27; -typedef std::array< bool, 2 > bool_2 ; -typedef std::array< bool, 3 > bool_3 ; -typedef std::array< bool, 4 > bool_4 ; -typedef std::array< bool, 5 > bool_5 ; -typedef std::array< bool, 6 > bool_6 ; -typedef std::array< bool, 7 > bool_7 ; -typedef std::array< bool, 8 > bool_8 ; -typedef std::array< bool, 9 > bool_9 ; -typedef std::array< bool, 10 > bool_10; -typedef std::array< bool, 11 > bool_11; -typedef std::array< bool, 12 > bool_12; -typedef std::array< bool, 13 > bool_13; -typedef std::array< bool, 14 > bool_14; -typedef std::array< bool, 15 > bool_15; -typedef std::array< bool, 16 > bool_16; -typedef std::array< bool, 17 > bool_17; -typedef std::array< bool, 18 > bool_18; -typedef std::array< bool, 19 > bool_19; -typedef std::array< bool, 20 > bool_20; -typedef std::array< bool, 21 > bool_21; -typedef std::array< bool, 22 > bool_22; -typedef std::array< bool, 23 > bool_23; -typedef std::array< bool, 24 > bool_24; -typedef std::array< bool, 25 > bool_25; -typedef std::array< bool, 26 > bool_26; -typedef std::array< bool, 27 > bool_27; +typedef std::array<bool, 2> bool_2; +typedef std::array<bool, 3> bool_3; +typedef std::array<bool, 4> bool_4; +typedef std::array<bool, 5> bool_5; +typedef std::array<bool, 6> bool_6; +typedef std::array<bool, 7> bool_7; +typedef std::array<bool, 8> bool_8; +typedef std::array<bool, 9> bool_9; +typedef std::array<bool, 10> bool_10; +typedef std::array<bool, 11> bool_11; +typedef std::array<bool, 12> bool_12; +typedef std::array<bool, 13> bool_13; +typedef std::array<bool, 14> bool_14; +typedef std::array<bool, 15> bool_15; +typedef std::array<bool, 16> bool_16; +typedef std::array<bool, 17> bool_17; +typedef std::array<bool, 18> bool_18; +typedef std::array<bool, 19> bool_19; +typedef std::array<bool, 20> bool_20; +typedef std::array<bool, 21> bool_21; +typedef std::array<bool, 22> bool_22; +typedef std::array<bool, 23> bool_23; +typedef std::array<bool, 24> bool_24; +typedef std::array<bool, 25> bool_25; +typedef std::array<bool, 26> bool_26; +typedef std::array<bool, 27> bool_27; #endif diff --git a/src/basics/Core/DataTypes.h b/src/basics/Core/DataTypes.h index b4fa3a0d9..1ea72d2a8 100644 --- a/src/basics/Core/DataTypes.h +++ b/src/basics/Core/DataTypes.h @@ -3,7 +3,6 @@ #include <string> - #ifdef VF_DOUBLE_ACCURACY typedef double real; #else @@ -11,6 +10,6 @@ using real = float; #endif using uint = unsigned int; -#define INVALID_INDEX 4294967295 //max uint +#define INVALID_INDEX 4294967295 // max uint #endif diff --git a/src/basics/Core/Input/ConfigData/ConfigData.h b/src/basics/Core/Input/ConfigData/ConfigData.h index 16f789ef9..44d505576 100644 --- a/src/basics/Core/Input/ConfigData/ConfigData.h +++ b/src/basics/Core/Input/ConfigData/ConfigData.h @@ -11,177 +11,175 @@ class ConfigData public: virtual ~ConfigData() = default; - virtual real getViscosity() = 0; - virtual uint getNumberOfDevices() = 0; - virtual std::vector<uint> getDevices() = 0; - virtual std::string getOutputPath() = 0; - virtual std::string getPrefix() = 0; - virtual std::string getGridPath() = 0; - virtual bool getPrintOutputFiles() = 0; - virtual bool getGeometryValues() = 0; - virtual bool getCalc2ndOrderMoments() = 0; - virtual bool getCalc3rdOrderMoments() = 0; - virtual bool getCalcHighOrderMoments() = 0; - virtual bool getReadGeo() = 0; - virtual bool getCalcMedian() = 0; - virtual bool getCalcDragLift() = 0; - virtual bool getCalcCp() = 0; - virtual bool getWriteVeloASCIIfiles() = 0; - virtual bool getCalcPlaneConc() = 0; - virtual bool getConcFile() = 0; - virtual bool getStreetVelocityFile() = 0; - virtual bool getUseMeasurePoints() = 0; - virtual bool getUseWale() = 0; - virtual bool getUseInitNeq() = 0; - virtual bool getSimulatePorousMedia() = 0; - virtual uint getD3Qxx() = 0; - virtual uint getTEnd() = 0; - virtual uint getTOut() = 0; - virtual uint getTStartOut() = 0; - virtual uint getTimeCalcMedStart() = 0; - virtual uint getTimeCalcMedEnd() = 0; - virtual uint getPressInID() = 0; - virtual uint getPressOutID() = 0; - virtual uint getPressInZ() = 0; - virtual uint getPressOutZ() = 0; - virtual bool getDiffOn() = 0; - virtual uint getDiffMod() = 0; - virtual real getDiffusivity() = 0; - virtual real getTemperatureInit() = 0; - virtual real getTemperatureBC() = 0; - virtual real getVelocity() = 0; - virtual real getViscosityRatio() = 0; - virtual real getVelocityRatio() = 0; - virtual real getDensityRatio() = 0; - virtual real getPressRatio() = 0; - virtual real getRealX() = 0; - virtual real getRealY() = 0; - virtual real getFactorPressBC() = 0; - virtual std::string getGeometryFileC() = 0; - virtual std::string getGeometryFileM() = 0; - virtual std::string getGeometryFileF() = 0; - virtual uint getClockCycleForMP() = 0; - virtual uint getTimestepForMP() = 0; - virtual real getForcingX() = 0; - virtual real getForcingY() = 0; - virtual real getForcingZ() = 0; - virtual real getQuadricLimiterP() = 0; - virtual real getQuadricLimiterM() = 0; - virtual real getQuadricLimiterD() = 0; - virtual bool getCalcParticles() = 0; - virtual int getParticleBasicLevel() = 0; - virtual int getParticleInitLevel() = 0; - virtual int getNumberOfParticles() = 0; - virtual real getStartXHotWall() = 0; - virtual real getEndXHotWall() = 0; - virtual std::vector<std::string> getPossNeighborFilesX() = 0; - virtual std::vector<std::string> getPossNeighborFilesY() = 0; - virtual std::vector<std::string> getPossNeighborFilesZ() = 0; - //virtual std::vector<std::string> getPossNeighborFilesX() = 0; - //virtual std::vector<std::string> getPossNeighborFilesY() = 0; - //virtual std::vector<std::string> getPossNeighborFilesZ() = 0; - virtual int getTimeDoCheckPoint() = 0; - virtual int getTimeDoRestart() = 0; - virtual bool getDoCheckPoint() = 0; - virtual bool getDoRestart() = 0; - virtual uint getMaxLevel() = 0; - virtual std::vector<int> getGridX() = 0; - virtual std::vector<int> getGridY() = 0; - virtual std::vector<int> getGridZ() = 0; - virtual std::vector<int> getDistX() = 0; - virtual std::vector<int> getDistY() = 0; - virtual std::vector<int> getDistZ() = 0; - virtual std::vector<bool> getNeedInterface() = 0; - virtual std::string getMainKernel() = 0; - virtual bool getMultiKernelOn() = 0; - virtual std::vector<int> getMultiKernelLevel() = 0; - virtual std::vector<std::string>getMultiKernelName() = 0; - - virtual bool isViscosityInConfigFile() = 0; - virtual bool isNumberOfDevicesInConfigFile() = 0; - virtual bool isDevicesInConfigFile() = 0; - virtual bool isOutputPathInConfigFile() = 0; - virtual bool isPrefixInConfigFile() = 0; - virtual bool isGridPathInConfigFile() = 0; - virtual bool isPrintOutputFilesInConfigFile() = 0; - virtual bool isGeometryValuesInConfigFile() = 0; - virtual bool isCalc2ndOrderMomentsInConfigFile() = 0; - virtual bool isCalc3rdOrderMomentsInConfigFile() = 0; - virtual bool isCalcHighOrderMomentsInConfigFile() = 0; - virtual bool isReadGeoInConfigFile() = 0; - virtual bool isCalcMedianInConfigFile() = 0; - virtual bool isCalcDragLiftInConfigFile() = 0; - virtual bool isCalcCpInConfigFile() = 0; - virtual bool isWriteVeloASCIIfilesInConfigFile() = 0; - virtual bool isCalcPlaneConcInConfigFile() = 0; - virtual bool isConcFileInConfigFile() = 0; - virtual bool isStreetVelocityFileInConfigFile() = 0; - virtual bool isUseMeasurePointsInConfigFile() = 0; - virtual bool isUseWaleInConfigFile() = 0; - virtual bool isUseInitNeqInConfigFile() = 0; - virtual bool isSimulatePorousMediaInConfigFile() = 0; - virtual bool isD3QxxInConfigFile() = 0; - virtual bool isTEndInConfigFile() = 0; - virtual bool isTOutInConfigFile() = 0; - virtual bool isTStartOutInConfigFile() = 0; - virtual bool isTimeCalcMedStartInConfigFile() = 0; - virtual bool isTimeCalcMedEndInConfigFile() = 0; - virtual bool isPressInIDInConfigFile() = 0; - virtual bool isPressOutIDInConfigFile() = 0; - virtual bool isPressInZInConfigFile() = 0; - virtual bool isPressOutZInConfigFile() = 0; - virtual bool isDiffOnInConfigFile() = 0; - virtual bool isDiffModInConfigFile() = 0; - virtual bool isDiffusivityInConfigFile() = 0; - virtual bool isTemperatureInitInConfigFile() = 0; - virtual bool isTemperatureBCInConfigFile() = 0; - //virtual bool isViscosityInConfigFile() = 0; - virtual bool isVelocityInConfigFile() = 0; - virtual bool isViscosityRatioInConfigFile() = 0; - virtual bool isVelocityRatioInConfigFile() = 0; - virtual bool isDensityRatioInConfigFile() = 0; - virtual bool isPressRatioInConfigFile() = 0; - virtual bool isRealXInConfigFile() = 0; - virtual bool isRealYInConfigFile() = 0; - virtual bool isFactorPressBCInConfigFile() = 0; - virtual bool isGeometryFileCInConfigFile() = 0; - virtual bool isGeometryFileMInConfigFile() = 0; - virtual bool isGeometryFileFInConfigFile() = 0; - virtual bool isClockCycleForMPInConfigFile() = 0; - virtual bool isTimestepForMPInConfigFile() = 0; - virtual bool isForcingXInConfigFile() = 0; - virtual bool isForcingYInConfigFile() = 0; - virtual bool isForcingZInConfigFile() = 0; - virtual bool isQuadricLimiterPInConfigFile() = 0; - virtual bool isQuadricLimiterMInConfigFile() = 0; - virtual bool isQuadricLimiterDInConfigFile() = 0; - virtual bool isCalcParticlesInConfigFile() = 0; - virtual bool isParticleBasicLevelInConfigFile() = 0; - virtual bool isParticleInitLevelInConfigFile() = 0; - virtual bool isNumberOfParticlesInConfigFile() = 0; - virtual bool isNeighborWSBInConfigFile() = 0; - virtual bool isStartXHotWallInConfigFile() = 0; - virtual bool isEndXHotWallInConfigFile() = 0; - virtual bool isPossNeighborFilesXInConfigFile() = 0; - virtual bool isPossNeighborFilesYInConfigFile() = 0; - virtual bool isPossNeighborFilesZInConfigFile() = 0; - virtual bool isTimeDoCheckPointInConfigFile() = 0; - virtual bool isTimeDoRestartInConfigFile() = 0; - virtual bool isDoCheckPointInConfigFile() = 0; - virtual bool isDoRestartInConfigFile() = 0; - virtual bool isMaxLevelInConfigFile() = 0; - virtual bool isGridXInConfigFile() = 0; - virtual bool isGridYInConfigFile() = 0; - virtual bool isGridZInConfigFile() = 0; - virtual bool isDistXInConfigFile() = 0; - virtual bool isDistYInConfigFile() = 0; - virtual bool isDistZInConfigFile() = 0; - virtual bool isNeedInterfaceInConfigFile() = 0; - virtual bool isMainKernelInConfigFile() = 0; - virtual bool isMultiKernelOnInConfigFile() = 0; - virtual bool isMultiKernelLevelInConfigFile() = 0; - virtual bool isMultiKernelNameInConfigFile() = 0; - + virtual real getViscosity() = 0; + virtual uint getNumberOfDevices() = 0; + virtual std::vector<uint> getDevices() = 0; + virtual std::string getOutputPath() = 0; + virtual std::string getPrefix() = 0; + virtual std::string getGridPath() = 0; + virtual bool getPrintOutputFiles() = 0; + virtual bool getGeometryValues() = 0; + virtual bool getCalc2ndOrderMoments() = 0; + virtual bool getCalc3rdOrderMoments() = 0; + virtual bool getCalcHighOrderMoments() = 0; + virtual bool getReadGeo() = 0; + virtual bool getCalcMedian() = 0; + virtual bool getCalcDragLift() = 0; + virtual bool getCalcCp() = 0; + virtual bool getWriteVeloASCIIfiles() = 0; + virtual bool getCalcPlaneConc() = 0; + virtual bool getConcFile() = 0; + virtual bool getStreetVelocityFile() = 0; + virtual bool getUseMeasurePoints() = 0; + virtual bool getUseWale() = 0; + virtual bool getUseInitNeq() = 0; + virtual bool getSimulatePorousMedia() = 0; + virtual uint getD3Qxx() = 0; + virtual uint getTEnd() = 0; + virtual uint getTOut() = 0; + virtual uint getTStartOut() = 0; + virtual uint getTimeCalcMedStart() = 0; + virtual uint getTimeCalcMedEnd() = 0; + virtual uint getPressInID() = 0; + virtual uint getPressOutID() = 0; + virtual uint getPressInZ() = 0; + virtual uint getPressOutZ() = 0; + virtual bool getDiffOn() = 0; + virtual uint getDiffMod() = 0; + virtual real getDiffusivity() = 0; + virtual real getTemperatureInit() = 0; + virtual real getTemperatureBC() = 0; + virtual real getVelocity() = 0; + virtual real getViscosityRatio() = 0; + virtual real getVelocityRatio() = 0; + virtual real getDensityRatio() = 0; + virtual real getPressRatio() = 0; + virtual real getRealX() = 0; + virtual real getRealY() = 0; + virtual real getFactorPressBC() = 0; + virtual std::string getGeometryFileC() = 0; + virtual std::string getGeometryFileM() = 0; + virtual std::string getGeometryFileF() = 0; + virtual uint getClockCycleForMP() = 0; + virtual uint getTimestepForMP() = 0; + virtual real getForcingX() = 0; + virtual real getForcingY() = 0; + virtual real getForcingZ() = 0; + virtual real getQuadricLimiterP() = 0; + virtual real getQuadricLimiterM() = 0; + virtual real getQuadricLimiterD() = 0; + virtual bool getCalcParticles() = 0; + virtual int getParticleBasicLevel() = 0; + virtual int getParticleInitLevel() = 0; + virtual int getNumberOfParticles() = 0; + virtual real getStartXHotWall() = 0; + virtual real getEndXHotWall() = 0; + virtual std::vector<std::string> getPossNeighborFilesX() = 0; + virtual std::vector<std::string> getPossNeighborFilesY() = 0; + virtual std::vector<std::string> getPossNeighborFilesZ() = 0; + // virtual std::vector<std::string> getPossNeighborFilesX() = 0; + // virtual std::vector<std::string> getPossNeighborFilesY() = 0; + // virtual std::vector<std::string> getPossNeighborFilesZ() = 0; + virtual int getTimeDoCheckPoint() = 0; + virtual int getTimeDoRestart() = 0; + virtual bool getDoCheckPoint() = 0; + virtual bool getDoRestart() = 0; + virtual uint getMaxLevel() = 0; + virtual std::vector<int> getGridX() = 0; + virtual std::vector<int> getGridY() = 0; + virtual std::vector<int> getGridZ() = 0; + virtual std::vector<int> getDistX() = 0; + virtual std::vector<int> getDistY() = 0; + virtual std::vector<int> getDistZ() = 0; + virtual std::vector<bool> getNeedInterface() = 0; + virtual std::string getMainKernel() = 0; + virtual bool getMultiKernelOn() = 0; + virtual std::vector<int> getMultiKernelLevel() = 0; + virtual std::vector<std::string> getMultiKernelName() = 0; + virtual bool isViscosityInConfigFile() = 0; + virtual bool isNumberOfDevicesInConfigFile() = 0; + virtual bool isDevicesInConfigFile() = 0; + virtual bool isOutputPathInConfigFile() = 0; + virtual bool isPrefixInConfigFile() = 0; + virtual bool isGridPathInConfigFile() = 0; + virtual bool isPrintOutputFilesInConfigFile() = 0; + virtual bool isGeometryValuesInConfigFile() = 0; + virtual bool isCalc2ndOrderMomentsInConfigFile() = 0; + virtual bool isCalc3rdOrderMomentsInConfigFile() = 0; + virtual bool isCalcHighOrderMomentsInConfigFile() = 0; + virtual bool isReadGeoInConfigFile() = 0; + virtual bool isCalcMedianInConfigFile() = 0; + virtual bool isCalcDragLiftInConfigFile() = 0; + virtual bool isCalcCpInConfigFile() = 0; + virtual bool isWriteVeloASCIIfilesInConfigFile() = 0; + virtual bool isCalcPlaneConcInConfigFile() = 0; + virtual bool isConcFileInConfigFile() = 0; + virtual bool isStreetVelocityFileInConfigFile() = 0; + virtual bool isUseMeasurePointsInConfigFile() = 0; + virtual bool isUseWaleInConfigFile() = 0; + virtual bool isUseInitNeqInConfigFile() = 0; + virtual bool isSimulatePorousMediaInConfigFile() = 0; + virtual bool isD3QxxInConfigFile() = 0; + virtual bool isTEndInConfigFile() = 0; + virtual bool isTOutInConfigFile() = 0; + virtual bool isTStartOutInConfigFile() = 0; + virtual bool isTimeCalcMedStartInConfigFile() = 0; + virtual bool isTimeCalcMedEndInConfigFile() = 0; + virtual bool isPressInIDInConfigFile() = 0; + virtual bool isPressOutIDInConfigFile() = 0; + virtual bool isPressInZInConfigFile() = 0; + virtual bool isPressOutZInConfigFile() = 0; + virtual bool isDiffOnInConfigFile() = 0; + virtual bool isDiffModInConfigFile() = 0; + virtual bool isDiffusivityInConfigFile() = 0; + virtual bool isTemperatureInitInConfigFile() = 0; + virtual bool isTemperatureBCInConfigFile() = 0; + // virtual bool isViscosityInConfigFile() = 0; + virtual bool isVelocityInConfigFile() = 0; + virtual bool isViscosityRatioInConfigFile() = 0; + virtual bool isVelocityRatioInConfigFile() = 0; + virtual bool isDensityRatioInConfigFile() = 0; + virtual bool isPressRatioInConfigFile() = 0; + virtual bool isRealXInConfigFile() = 0; + virtual bool isRealYInConfigFile() = 0; + virtual bool isFactorPressBCInConfigFile() = 0; + virtual bool isGeometryFileCInConfigFile() = 0; + virtual bool isGeometryFileMInConfigFile() = 0; + virtual bool isGeometryFileFInConfigFile() = 0; + virtual bool isClockCycleForMPInConfigFile() = 0; + virtual bool isTimestepForMPInConfigFile() = 0; + virtual bool isForcingXInConfigFile() = 0; + virtual bool isForcingYInConfigFile() = 0; + virtual bool isForcingZInConfigFile() = 0; + virtual bool isQuadricLimiterPInConfigFile() = 0; + virtual bool isQuadricLimiterMInConfigFile() = 0; + virtual bool isQuadricLimiterDInConfigFile() = 0; + virtual bool isCalcParticlesInConfigFile() = 0; + virtual bool isParticleBasicLevelInConfigFile() = 0; + virtual bool isParticleInitLevelInConfigFile() = 0; + virtual bool isNumberOfParticlesInConfigFile() = 0; + virtual bool isNeighborWSBInConfigFile() = 0; + virtual bool isStartXHotWallInConfigFile() = 0; + virtual bool isEndXHotWallInConfigFile() = 0; + virtual bool isPossNeighborFilesXInConfigFile() = 0; + virtual bool isPossNeighborFilesYInConfigFile() = 0; + virtual bool isPossNeighborFilesZInConfigFile() = 0; + virtual bool isTimeDoCheckPointInConfigFile() = 0; + virtual bool isTimeDoRestartInConfigFile() = 0; + virtual bool isDoCheckPointInConfigFile() = 0; + virtual bool isDoRestartInConfigFile() = 0; + virtual bool isMaxLevelInConfigFile() = 0; + virtual bool isGridXInConfigFile() = 0; + virtual bool isGridYInConfigFile() = 0; + virtual bool isGridZInConfigFile() = 0; + virtual bool isDistXInConfigFile() = 0; + virtual bool isDistYInConfigFile() = 0; + virtual bool isDistZInConfigFile() = 0; + virtual bool isNeedInterfaceInConfigFile() = 0; + virtual bool isMainKernelInConfigFile() = 0; + virtual bool isMultiKernelOnInConfigFile() = 0; + virtual bool isMultiKernelLevelInConfigFile() = 0; + virtual bool isMultiKernelNameInConfigFile() = 0; }; #endif diff --git a/src/basics/Core/Input/ConfigData/ConfigDataImp.cpp b/src/basics/Core/Input/ConfigData/ConfigDataImp.cpp index 35652c2eb..7e0e09361 100644 --- a/src/basics/Core/Input/ConfigData/ConfigDataImp.cpp +++ b/src/basics/Core/Input/ConfigData/ConfigDataImp.cpp @@ -1,731 +1,483 @@ #include "ConfigDataImp.h" - std::shared_ptr<ConfigDataImp> ConfigDataImp::getNewInstance() { - return std::shared_ptr<ConfigDataImp>(new ConfigDataImp()); + return std::shared_ptr<ConfigDataImp>(new ConfigDataImp()); } ConfigDataImp::ConfigDataImp() { - this->isViscosity=false; - this->isNumberOfDevices=false; - this->isDevices=false; - this->isOutputPath=false; - this->isPrefix=false; - this->isGridPath=false; - this->isPrintOutputFiles=false; - this->isGeometryValues=false; - this->isCalc2ndOrderMoments=false; - this->isCalc3rdOrderMoments=false; - this->isCalcHighOrderMoments=false; - this->isReadGeo=false; - this->isCalcMedian=false; - this->isCalcDragLift = false; - this->isCalcCp = false; - this->isConcFile=false; - this->isUseMeasurePoints=false; - this->isUseWale=false; - this->isSimulatePorousMedia=false; - this->isD3Qxx=false; - this->isTEnd=false; - this->isTOut=false; - this->isTStartOut=false; - this->isTimeCalcMedStart=false; - this->isTimeCalcMedEnd=false; - this->isPressInID=false; - this->isPressOutID=false; - this->isPressInZ=false; - this->isPressOutZ=false; - this->isDiffOn=false; - this->isDiffMod=false; - this->isDiffusivity=false; - this->isTemperatureInit=false; - this->isTemperatureBC=false; - this->isVelocity=false; - this->isViscosityRatio=false; - this->isVelocityRatio=false; - this->isDensityRatio=false; - this->isPressRatio=false; - this->isRealX=false; - this->isRealY=false; - this->isFactorPressBC=false; - this->isGeometryFileC=false; - this->isGeometryFileM=false; - this->isGeometryFileF=false; - this->isClockCycleForMP=false; - this->isTimestepForMP=false; - this->isForcingX=false; - this->isForcingY=false; - this->isForcingZ=false; - this->isCalcParticles=false; - this->isParticleBasicLevel=false; - this->isParticleInitLevel=false; - this->isNumberOfParticles=false; - this->isNeighborWSB=false; - this->isStartXHotWall=false; - this->isEndXHotWall=false; - this->isPossNeighborFilesX=false; - this->isPossNeighborFilesY=false; - this->isPossNeighborFilesZ=false; - this->isTimeDoCheckPoint=false; - this->isTimeDoRestart=false; - this->isDoCheckPoint=false; - this->isDoRestart=false; - this->isMaxLevel=false; - this->isGridX=false; - this->isGridY=false; - this->isGridZ=false; - this->isDistX=false; - this->isDistY=false; - this->isDistZ=false; - this->isNeedInterface=false; - this->isMainKernel=false; - this->isMultiKernelOn=false; - this->isMultiKernelLevel=false; - this->isMultiKernelName=false; - + this->isViscosity = false; + this->isNumberOfDevices = false; + this->isDevices = false; + this->isOutputPath = false; + this->isPrefix = false; + this->isGridPath = false; + this->isPrintOutputFiles = false; + this->isGeometryValues = false; + this->isCalc2ndOrderMoments = false; + this->isCalc3rdOrderMoments = false; + this->isCalcHighOrderMoments = false; + this->isReadGeo = false; + this->isCalcMedian = false; + this->isCalcDragLift = false; + this->isCalcCp = false; + this->isConcFile = false; + this->isUseMeasurePoints = false; + this->isUseWale = false; + this->isSimulatePorousMedia = false; + this->isD3Qxx = false; + this->isTEnd = false; + this->isTOut = false; + this->isTStartOut = false; + this->isTimeCalcMedStart = false; + this->isTimeCalcMedEnd = false; + this->isPressInID = false; + this->isPressOutID = false; + this->isPressInZ = false; + this->isPressOutZ = false; + this->isDiffOn = false; + this->isDiffMod = false; + this->isDiffusivity = false; + this->isTemperatureInit = false; + this->isTemperatureBC = false; + this->isVelocity = false; + this->isViscosityRatio = false; + this->isVelocityRatio = false; + this->isDensityRatio = false; + this->isPressRatio = false; + this->isRealX = false; + this->isRealY = false; + this->isFactorPressBC = false; + this->isGeometryFileC = false; + this->isGeometryFileM = false; + this->isGeometryFileF = false; + this->isClockCycleForMP = false; + this->isTimestepForMP = false; + this->isForcingX = false; + this->isForcingY = false; + this->isForcingZ = false; + this->isCalcParticles = false; + this->isParticleBasicLevel = false; + this->isParticleInitLevel = false; + this->isNumberOfParticles = false; + this->isNeighborWSB = false; + this->isStartXHotWall = false; + this->isEndXHotWall = false; + this->isPossNeighborFilesX = false; + this->isPossNeighborFilesY = false; + this->isPossNeighborFilesZ = false; + this->isTimeDoCheckPoint = false; + this->isTimeDoRestart = false; + this->isDoCheckPoint = false; + this->isDoRestart = false; + this->isMaxLevel = false; + this->isGridX = false; + this->isGridY = false; + this->isGridZ = false; + this->isDistX = false; + this->isDistY = false; + this->isDistZ = false; + this->isNeedInterface = false; + this->isMainKernel = false; + this->isMultiKernelOn = false; + this->isMultiKernelLevel = false; + this->isMultiKernelName = false; } -real ConfigDataImp::getViscosity() -{ - return this->viscosity; -} +real ConfigDataImp::getViscosity() { return this->viscosity; } -uint ConfigDataImp::getNumberOfDevices() -{ - return this->numberOfDevices; -} +uint ConfigDataImp::getNumberOfDevices() { return this->numberOfDevices; } -std::vector<uint> ConfigDataImp::getDevices() -{ - return this->devices; -} +std::vector<uint> ConfigDataImp::getDevices() { return this->devices; } -std::string ConfigDataImp::getOutputPath() -{ - return this->outputPath; -} +std::string ConfigDataImp::getOutputPath() { return this->outputPath; } -std::string ConfigDataImp::getPrefix() -{ - return this->prefix; -} +std::string ConfigDataImp::getPrefix() { return this->prefix; } -std::string ConfigDataImp::getGridPath() -{ - return this->gridPath; -} +std::string ConfigDataImp::getGridPath() { return this->gridPath; } -bool ConfigDataImp::getPrintOutputFiles() -{ - return this->printOutputFiles; -} +bool ConfigDataImp::getPrintOutputFiles() { return this->printOutputFiles; } -bool ConfigDataImp::getGeometryValues() -{ - return this->geometryValues; -} +bool ConfigDataImp::getGeometryValues() { return this->geometryValues; } -bool ConfigDataImp::getCalc2ndOrderMoments() -{ - return this->calc2ndOrderMoments; -} +bool ConfigDataImp::getCalc2ndOrderMoments() { return this->calc2ndOrderMoments; } -bool ConfigDataImp::getCalc3rdOrderMoments() -{ - return this->calc3rdOrderMoments; -} +bool ConfigDataImp::getCalc3rdOrderMoments() { return this->calc3rdOrderMoments; } -bool ConfigDataImp::getCalcHighOrderMoments() -{ - return this->calcHighOrderMoments; -} +bool ConfigDataImp::getCalcHighOrderMoments() { return this->calcHighOrderMoments; } -bool ConfigDataImp::getReadGeo() -{ - return this->readGeo; -} +bool ConfigDataImp::getReadGeo() { return this->readGeo; } -bool ConfigDataImp::getCalcMedian() -{ - return this->calcMedian; -} +bool ConfigDataImp::getCalcMedian() { return this->calcMedian; } -bool ConfigDataImp::getCalcDragLift() -{ - return this->calcDragLift; -} +bool ConfigDataImp::getCalcDragLift() { return this->calcDragLift; } -bool ConfigDataImp::getCalcCp() -{ - return this->calcCp; -} +bool ConfigDataImp::getCalcCp() { return this->calcCp; } -bool ConfigDataImp::getWriteVeloASCIIfiles() -{ - return this->writeVeloASCIIfiles; -} +bool ConfigDataImp::getWriteVeloASCIIfiles() { return this->writeVeloASCIIfiles; } -bool ConfigDataImp::getCalcPlaneConc() -{ - return this->calcPlaneConc; -} +bool ConfigDataImp::getCalcPlaneConc() { return this->calcPlaneConc; } -bool ConfigDataImp::getConcFile() -{ - return this->concFile; -} +bool ConfigDataImp::getConcFile() { return this->concFile; } -bool ConfigDataImp::getStreetVelocityFile() -{ - return this->streetVelocityFile; -} +bool ConfigDataImp::getStreetVelocityFile() { return this->streetVelocityFile; } -bool ConfigDataImp::getUseMeasurePoints() -{ - return this->useMeasurePoints; -} +bool ConfigDataImp::getUseMeasurePoints() { return this->useMeasurePoints; } -bool ConfigDataImp::getUseWale() -{ - return this->useWale; -} +bool ConfigDataImp::getUseWale() { return this->useWale; } -bool ConfigDataImp::getUseInitNeq() -{ - return this->useInitNeq; -} +bool ConfigDataImp::getUseInitNeq() { return this->useInitNeq; } -bool ConfigDataImp::getSimulatePorousMedia() -{ - return this->simulatePorousMedia; -} +bool ConfigDataImp::getSimulatePorousMedia() { return this->simulatePorousMedia; } -uint ConfigDataImp::getD3Qxx() -{ - return this->d3Qxx; -} +uint ConfigDataImp::getD3Qxx() { return this->d3Qxx; } -uint ConfigDataImp::getTEnd() -{ - return this->tEnd; -} +uint ConfigDataImp::getTEnd() { return this->tEnd; } -uint ConfigDataImp::getTOut() -{ - return this->tOut; -} +uint ConfigDataImp::getTOut() { return this->tOut; } -uint ConfigDataImp::getTStartOut() -{ - return this->tStartOut; -} +uint ConfigDataImp::getTStartOut() { return this->tStartOut; } -uint ConfigDataImp::getTimeCalcMedStart() -{ - return this->timeCalcMedStart; -} +uint ConfigDataImp::getTimeCalcMedStart() { return this->timeCalcMedStart; } -uint ConfigDataImp::getTimeCalcMedEnd() -{ - return this->timeCalcMedEnd; -} +uint ConfigDataImp::getTimeCalcMedEnd() { return this->timeCalcMedEnd; } -uint ConfigDataImp::getPressInID() -{ - return this->pressInID; -} +uint ConfigDataImp::getPressInID() { return this->pressInID; } -uint ConfigDataImp::getPressOutID() -{ - return this->pressOutID; -} +uint ConfigDataImp::getPressOutID() { return this->pressOutID; } -uint ConfigDataImp::getPressInZ() -{ - return this->pressInZ; -} +uint ConfigDataImp::getPressInZ() { return this->pressInZ; } -uint ConfigDataImp::getPressOutZ() -{ - return this->pressOutZ; -} +uint ConfigDataImp::getPressOutZ() { return this->pressOutZ; } -bool ConfigDataImp::getDiffOn() -{ - return this->diffOn; -} +bool ConfigDataImp::getDiffOn() { return this->diffOn; } -uint ConfigDataImp::getDiffMod() -{ - return this->diffMod; -} +uint ConfigDataImp::getDiffMod() { return this->diffMod; } -real ConfigDataImp::getDiffusivity() -{ - return this->diffusivity; -} +real ConfigDataImp::getDiffusivity() { return this->diffusivity; } -real ConfigDataImp::getTemperatureInit() -{ - return this->temperatureInit; -} +real ConfigDataImp::getTemperatureInit() { return this->temperatureInit; } -real ConfigDataImp::getTemperatureBC() -{ - return this->temperatureBC; -} +real ConfigDataImp::getTemperatureBC() { return this->temperatureBC; } -real ConfigDataImp::getVelocity() -{ - return this->velocity; -} +real ConfigDataImp::getVelocity() { return this->velocity; } -real ConfigDataImp::getViscosityRatio() -{ - return this->viscosityRatio; -} +real ConfigDataImp::getViscosityRatio() { return this->viscosityRatio; } -real ConfigDataImp::getVelocityRatio() -{ - return this->velocityRatio; -} +real ConfigDataImp::getVelocityRatio() { return this->velocityRatio; } -real ConfigDataImp::getDensityRatio() -{ - return this->densityRatio; -} +real ConfigDataImp::getDensityRatio() { return this->densityRatio; } -real ConfigDataImp::getPressRatio() -{ - return this->pressRatio; -} +real ConfigDataImp::getPressRatio() { return this->pressRatio; } -real ConfigDataImp::getRealX() -{ - return this->realX; -} +real ConfigDataImp::getRealX() { return this->realX; } -real ConfigDataImp::getRealY() -{ - return this->realY; -} +real ConfigDataImp::getRealY() { return this->realY; } -real ConfigDataImp::getFactorPressBC() -{ - return this->factorPressBC; -} +real ConfigDataImp::getFactorPressBC() { return this->factorPressBC; } -std::string ConfigDataImp::getGeometryFileC() -{ - return this->geometryFileC; -} +std::string ConfigDataImp::getGeometryFileC() { return this->geometryFileC; } -std::string ConfigDataImp::getGeometryFileM() -{ - return this->geometryFileM; -} +std::string ConfigDataImp::getGeometryFileM() { return this->geometryFileM; } -std::string ConfigDataImp::getGeometryFileF() -{ - return this->geometryFileF; -} +std::string ConfigDataImp::getGeometryFileF() { return this->geometryFileF; } -uint ConfigDataImp::getClockCycleForMP() -{ - return this->clockCycleForMP; -} +uint ConfigDataImp::getClockCycleForMP() { return this->clockCycleForMP; } -uint ConfigDataImp::getTimestepForMP() -{ - return this->timestepForMP; -} +uint ConfigDataImp::getTimestepForMP() { return this->timestepForMP; } -real ConfigDataImp::getForcingX() -{ - return this->forcingX; -} +real ConfigDataImp::getForcingX() { return this->forcingX; } -real ConfigDataImp::getForcingY() -{ - return this->forcingY; -} +real ConfigDataImp::getForcingY() { return this->forcingY; } -real ConfigDataImp::getForcingZ() -{ - return this->forcingZ; -} +real ConfigDataImp::getForcingZ() { return this->forcingZ; } -real ConfigDataImp::getQuadricLimiterP() -{ - return this->quadricLimiterP; -} +real ConfigDataImp::getQuadricLimiterP() { return this->quadricLimiterP; } -real ConfigDataImp::getQuadricLimiterM() -{ - return this->quadricLimiterM; -} +real ConfigDataImp::getQuadricLimiterM() { return this->quadricLimiterM; } -real ConfigDataImp::getQuadricLimiterD() -{ - return this->quadricLimiterD; -} +real ConfigDataImp::getQuadricLimiterD() { return this->quadricLimiterD; } -bool ConfigDataImp::getCalcParticles() -{ - return this->calcParticles; -} +bool ConfigDataImp::getCalcParticles() { return this->calcParticles; } -int ConfigDataImp::getParticleBasicLevel() -{ - return this->particleBasicLevel; -} +int ConfigDataImp::getParticleBasicLevel() { return this->particleBasicLevel; } -int ConfigDataImp::getParticleInitLevel() -{ - return this->particleInitLevel; -} +int ConfigDataImp::getParticleInitLevel() { return this->particleInitLevel; } -int ConfigDataImp::getNumberOfParticles() -{ - return this->numberOfParticles; -} +int ConfigDataImp::getNumberOfParticles() { return this->numberOfParticles; } -real ConfigDataImp::getStartXHotWall() -{ - return this->startXHotWall; -} +real ConfigDataImp::getStartXHotWall() { return this->startXHotWall; } -real ConfigDataImp::getEndXHotWall() -{ - return this->endXHotWall; -} +real ConfigDataImp::getEndXHotWall() { return this->endXHotWall; } -std::vector<std::string> ConfigDataImp::getPossNeighborFilesX() -{ - return this->possNeighborFilesX; -} +std::vector<std::string> ConfigDataImp::getPossNeighborFilesX() { return this->possNeighborFilesX; } -std::vector<std::string> ConfigDataImp::getPossNeighborFilesY() -{ - return this->possNeighborFilesY; -} +std::vector<std::string> ConfigDataImp::getPossNeighborFilesY() { return this->possNeighborFilesY; } -std::vector<std::string> ConfigDataImp::getPossNeighborFilesZ() -{ - return this->possNeighborFilesZ; -} +std::vector<std::string> ConfigDataImp::getPossNeighborFilesZ() { return this->possNeighborFilesZ; } -int ConfigDataImp::getTimeDoCheckPoint() -{ - return this->timeDoCheckPoint; -} +int ConfigDataImp::getTimeDoCheckPoint() { return this->timeDoCheckPoint; } -int ConfigDataImp::getTimeDoRestart() -{ - return this->timeDoRestart; -} +int ConfigDataImp::getTimeDoRestart() { return this->timeDoRestart; } -bool ConfigDataImp::getDoCheckPoint() -{ - return this->doCheckPoint; -} +bool ConfigDataImp::getDoCheckPoint() { return this->doCheckPoint; } -bool ConfigDataImp::getDoRestart() -{ - return this->doRestart; -} +bool ConfigDataImp::getDoRestart() { return this->doRestart; } -uint ConfigDataImp::getMaxLevel() -{ - return this->maxLevel; -} +uint ConfigDataImp::getMaxLevel() { return this->maxLevel; } -std::vector<int> ConfigDataImp::getGridX() -{ - return this->gridX; -} +std::vector<int> ConfigDataImp::getGridX() { return this->gridX; } -std::vector<int> ConfigDataImp::getGridY() -{ - return this->gridY; -} +std::vector<int> ConfigDataImp::getGridY() { return this->gridY; } -std::vector<int> ConfigDataImp::getGridZ() -{ - return this->gridZ; -} +std::vector<int> ConfigDataImp::getGridZ() { return this->gridZ; } -std::vector<int> ConfigDataImp::getDistX() -{ - return this->distX; -} +std::vector<int> ConfigDataImp::getDistX() { return this->distX; } -std::vector<int> ConfigDataImp::getDistY() -{ - return this->distY; -} +std::vector<int> ConfigDataImp::getDistY() { return this->distY; } -std::vector<int> ConfigDataImp::getDistZ() -{ - return this->distZ; -} +std::vector<int> ConfigDataImp::getDistZ() { return this->distZ; } -std::vector<bool> ConfigDataImp::getNeedInterface() -{ - return this->needInterface; -} +std::vector<bool> ConfigDataImp::getNeedInterface() { return this->needInterface; } -std::string ConfigDataImp::getMainKernel() -{ - return this->mainKernel; -} +std::string ConfigDataImp::getMainKernel() { return this->mainKernel; } -bool ConfigDataImp::getMultiKernelOn() -{ - return this->multiKernelOn; -} +bool ConfigDataImp::getMultiKernelOn() { return this->multiKernelOn; } -std::vector<int> ConfigDataImp::getMultiKernelLevel() -{ - return this->multiKernelLevel; -} +std::vector<int> ConfigDataImp::getMultiKernelLevel() { return this->multiKernelLevel; } -std::vector<std::string> ConfigDataImp::getMultiKernelName() -{ - return this->multiKernelName; -} +std::vector<std::string> ConfigDataImp::getMultiKernelName() { return this->multiKernelName; } void ConfigDataImp::setViscosity(real viscosity) { - this->viscosity = viscosity; - this->isViscosity = true; + this->viscosity = viscosity; + this->isViscosity = true; } void ConfigDataImp::setNumberOfDevices(uint numberOfDevices) { - this->numberOfDevices = numberOfDevices; - this->isNumberOfDevices = true; + this->numberOfDevices = numberOfDevices; + this->isNumberOfDevices = true; } void ConfigDataImp::setDevices(std::vector<uint> devices) { - this->devices = devices; - this->isDevices = true; + this->devices = devices; + this->isDevices = true; } void ConfigDataImp::setOutputPath(std::string outputPath) { - this->outputPath = outputPath; - this->isOutputPath = true; + this->outputPath = outputPath; + this->isOutputPath = true; } void ConfigDataImp::setPrefix(std::string prefix) { - this->prefix = prefix; - this->isPrefix = true; + this->prefix = prefix; + this->isPrefix = true; } void ConfigDataImp::setGridPath(std::string gridPath) { - this->gridPath = gridPath; - this->isGridPath = true; + this->gridPath = gridPath; + this->isGridPath = true; } void ConfigDataImp::setPrintOutputFiles(bool printOutputFiles) { - this->printOutputFiles = printOutputFiles; - this->isPrintOutputFiles = true; + this->printOutputFiles = printOutputFiles; + this->isPrintOutputFiles = true; } void ConfigDataImp::setGeometryValues(bool geometryValues) { - this->geometryValues = geometryValues; - this->isGeometryValues = true; + this->geometryValues = geometryValues; + this->isGeometryValues = true; } void ConfigDataImp::setCalc2ndOrderMoments(bool calc2ndOrderMoments) { - this->calc2ndOrderMoments = calc2ndOrderMoments; - this->isCalc2ndOrderMoments = true; + this->calc2ndOrderMoments = calc2ndOrderMoments; + this->isCalc2ndOrderMoments = true; } void ConfigDataImp::setCalc3rdOrderMoments(bool calc3rdOrderMoments) { - this->calc3rdOrderMoments = calc3rdOrderMoments; - this->isCalc3rdOrderMoments = true; + this->calc3rdOrderMoments = calc3rdOrderMoments; + this->isCalc3rdOrderMoments = true; } void ConfigDataImp::setCalcHighOrderMoments(bool calcHighOrderMoments) { - this->calcHighOrderMoments = calcHighOrderMoments; - this->isCalcHighOrderMoments = true; + this->calcHighOrderMoments = calcHighOrderMoments; + this->isCalcHighOrderMoments = true; } void ConfigDataImp::setReadGeo(bool readGeo) { - this->readGeo = readGeo; - this->isReadGeo = true; + this->readGeo = readGeo; + this->isReadGeo = true; } void ConfigDataImp::setCalcMedian(bool calcMedian) { - this->calcMedian = calcMedian; - this->isCalcMedian = true; + this->calcMedian = calcMedian; + this->isCalcMedian = true; } void ConfigDataImp::setCalcDragLift(bool calcDragLift) { - this->calcDragLift = calcDragLift; - this->isCalcDragLift = true; + this->calcDragLift = calcDragLift; + this->isCalcDragLift = true; } void ConfigDataImp::setCalcCp(bool calcCp) { - this->calcCp = calcCp; - this->isCalcCp = true; + this->calcCp = calcCp; + this->isCalcCp = true; } void ConfigDataImp::setWriteVeloASCIIfiles(bool writeVeloASCIIfiles) { - this->writeVeloASCIIfiles = writeVeloASCIIfiles; - this->isWriteVeloASCII = true; + this->writeVeloASCIIfiles = writeVeloASCIIfiles; + this->isWriteVeloASCII = true; } void ConfigDataImp::setCalcPlaneConc(bool calcPlaneConc) { - this->calcPlaneConc = calcPlaneConc; - this->isCalcPlaneConc = true; + this->calcPlaneConc = calcPlaneConc; + this->isCalcPlaneConc = true; } void ConfigDataImp::setConcFile(bool concFile) { - this->concFile = concFile; - this->isConcFile = true; + this->concFile = concFile; + this->isConcFile = true; } void ConfigDataImp::setStreetVelocityFile(bool streetVelocityFile) { - this->streetVelocityFile = streetVelocityFile; - this->isStreetVelocityFile = true; + this->streetVelocityFile = streetVelocityFile; + this->isStreetVelocityFile = true; } void ConfigDataImp::setUseMeasurePoints(bool useMeasurePoints) { - this->useMeasurePoints = useMeasurePoints; - this->isUseMeasurePoints = true; + this->useMeasurePoints = useMeasurePoints; + this->isUseMeasurePoints = true; } void ConfigDataImp::setUseWale(bool useWale) { - this->useWale = useWale; - this->isUseWale = true; + this->useWale = useWale; + this->isUseWale = true; } void ConfigDataImp::setUseInitNeq(bool useInitNeq) { - this->useInitNeq = useInitNeq; - this->isUseInitNeq = true; + this->useInitNeq = useInitNeq; + this->isUseInitNeq = true; } void ConfigDataImp::setSimulatePorousMedia(bool simulatePorousMedia) { - this->simulatePorousMedia = simulatePorousMedia; - this->isSimulatePorousMedia = true; + this->simulatePorousMedia = simulatePorousMedia; + this->isSimulatePorousMedia = true; } void ConfigDataImp::setD3Qxx(uint d3Qxx) { - this->d3Qxx = d3Qxx; - this->isD3Qxx = true; + this->d3Qxx = d3Qxx; + this->isD3Qxx = true; } void ConfigDataImp::setTEnd(uint tEnd) { - this->tEnd = tEnd; - this->isTEnd = true; + this->tEnd = tEnd; + this->isTEnd = true; } void ConfigDataImp::setTOut(uint tOut) { - this->tOut = tOut; - this->isTOut = true; + this->tOut = tOut; + this->isTOut = true; } void ConfigDataImp::setTStartOut(uint tStartOut) { - this->tStartOut = tStartOut; - this->isTStartOut = true; + this->tStartOut = tStartOut; + this->isTStartOut = true; } void ConfigDataImp::setTimeCalcMedStart(uint timeCalcMedStart) { - this->timeCalcMedStart = timeCalcMedStart; - this->isTimeCalcMedStart = true; + this->timeCalcMedStart = timeCalcMedStart; + this->isTimeCalcMedStart = true; } void ConfigDataImp::setTimeCalcMedEnd(uint timeCalcMedEnd) { - this->timeCalcMedEnd = timeCalcMedEnd; - this->isTimeCalcMedEnd = true; + this->timeCalcMedEnd = timeCalcMedEnd; + this->isTimeCalcMedEnd = true; } void ConfigDataImp::setPressInID(uint pressInID) { - this->pressInID = pressInID; - this->isPressInID = true; + this->pressInID = pressInID; + this->isPressInID = true; } void ConfigDataImp::setPressOutID(uint pressOutID) { - this->pressOutID = pressOutID; - this->isPressOutID = true; + this->pressOutID = pressOutID; + this->isPressOutID = true; } void ConfigDataImp::setPressInZ(uint pressInZ) { - this->pressInZ = pressInZ; - this->isPressInZ = true; + this->pressInZ = pressInZ; + this->isPressInZ = true; } void ConfigDataImp::setPressOutZ(uint pressOutZ) { - this->pressOutZ = pressOutZ; - this->isPressOutZ = true; + this->pressOutZ = pressOutZ; + this->isPressOutZ = true; } void ConfigDataImp::setDiffOn(bool diffOn) { - this->diffOn = diffOn; - this->isDiffOn = true; + this->diffOn = diffOn; + this->isDiffOn = true; } void ConfigDataImp::setDiffMod(uint diffMod) { - this->diffMod = diffMod; - this->isDiffMod = true; + this->diffMod = diffMod; + this->isDiffMod = true; } void ConfigDataImp::setDiffusivity(real diffusivity) { - this->diffusivity = diffusivity; - this->isDiffusivity = true; + this->diffusivity = diffusivity; + this->isDiffusivity = true; } void ConfigDataImp::setTemperatureInit(real temperatureInit) { - this->temperatureInit = temperatureInit; - this->isTemperatureInit = true; + this->temperatureInit = temperatureInit; + this->isTemperatureInit = true; } void ConfigDataImp::setTemperatureBC(real temperatureBC) { - this->temperatureBC = temperatureBC; - this->isTemperatureBC = true; + this->temperatureBC = temperatureBC; + this->isTemperatureBC = true; } -//void ConfigDataImp::setViscosity(real viscosity) +// void ConfigDataImp::setViscosity(real viscosity) //{ // this->viscosity = viscosity; // this->isViscosity = true; @@ -733,681 +485,430 @@ void ConfigDataImp::setTemperatureBC(real temperatureBC) void ConfigDataImp::setVelocity(real velocity) { - this->velocity = velocity; - this->isVelocity = true; + this->velocity = velocity; + this->isVelocity = true; } void ConfigDataImp::setViscosityRatio(real viscosityRatio) { - this->viscosityRatio = viscosityRatio; - this->isViscosityRatio = true; + this->viscosityRatio = viscosityRatio; + this->isViscosityRatio = true; } void ConfigDataImp::setVelocityRatio(real velocityRatio) { - this->velocityRatio = velocityRatio; - this->isVelocityRatio = true; + this->velocityRatio = velocityRatio; + this->isVelocityRatio = true; } void ConfigDataImp::setDensityRatio(real densityRatio) { - this->densityRatio = densityRatio; - this->isDensityRatio = true; + this->densityRatio = densityRatio; + this->isDensityRatio = true; } void ConfigDataImp::setPressRatio(real pressRatio) { - this->pressRatio = pressRatio; - this->isPressRatio = true; + this->pressRatio = pressRatio; + this->isPressRatio = true; } void ConfigDataImp::setRealX(real realX) { - this->realX = realX; - this->isRealX = true; + this->realX = realX; + this->isRealX = true; } void ConfigDataImp::setRealY(real realY) { - this->realY = realY; - this->isRealY = true; + this->realY = realY; + this->isRealY = true; } void ConfigDataImp::setFactorPressBC(real factorPressBC) { - this->factorPressBC = factorPressBC; - this->isFactorPressBC = true; + this->factorPressBC = factorPressBC; + this->isFactorPressBC = true; } void ConfigDataImp::setGeometryFileC(std::string geometryFileC) { - this->geometryFileC = geometryFileC; - this->isGeometryFileC = true; + this->geometryFileC = geometryFileC; + this->isGeometryFileC = true; } void ConfigDataImp::setGeometryFileM(std::string geometryFileM) { - this->geometryFileM = geometryFileM; - this->isGeometryFileM = true; + this->geometryFileM = geometryFileM; + this->isGeometryFileM = true; } void ConfigDataImp::setGeometryFileF(std::string geometryFileF) { - this->geometryFileF = geometryFileF; - this->isGeometryFileF = true; + this->geometryFileF = geometryFileF; + this->isGeometryFileF = true; } void ConfigDataImp::setClockCycleForMP(uint clockCycleForMP) { - this->clockCycleForMP = clockCycleForMP; - this->isClockCycleForMP = true; + this->clockCycleForMP = clockCycleForMP; + this->isClockCycleForMP = true; } void ConfigDataImp::setTimestepForMP(uint timestepForMP) { - this->timestepForMP = timestepForMP; - this->isTimestepForMP = true; + this->timestepForMP = timestepForMP; + this->isTimestepForMP = true; } void ConfigDataImp::setForcingX(real forcingX) { - this->forcingX = forcingX; - this->isForcingX = true; + this->forcingX = forcingX; + this->isForcingX = true; } void ConfigDataImp::setForcingY(real forcingY) { - this->forcingY = forcingY; - this->isForcingY = true; + this->forcingY = forcingY; + this->isForcingY = true; } void ConfigDataImp::setForcingZ(real forcingZ) { - this->forcingZ = forcingZ; - this->isForcingZ = true; + this->forcingZ = forcingZ; + this->isForcingZ = true; } void ConfigDataImp::setQuadricLimiterP(real quadricLimiterP) { - this->quadricLimiterP = quadricLimiterP; - this->isQuadricLimiterP = true; + this->quadricLimiterP = quadricLimiterP; + this->isQuadricLimiterP = true; } void ConfigDataImp::setQuadricLimiterM(real quadricLimiterM) { - this->quadricLimiterM = quadricLimiterM; - this->isQuadricLimiterM = true; + this->quadricLimiterM = quadricLimiterM; + this->isQuadricLimiterM = true; } void ConfigDataImp::setQuadricLimiterD(real quadricLimiterD) { - this->quadricLimiterD = quadricLimiterD; - this->isQuadricLimiterD = true; + this->quadricLimiterD = quadricLimiterD; + this->isQuadricLimiterD = true; } void ConfigDataImp::setCalcParticles(bool calcParticles) { - this->calcParticles = calcParticles; - this->isCalcParticles = true; + this->calcParticles = calcParticles; + this->isCalcParticles = true; } void ConfigDataImp::setParticleBasicLevel(int particleBasicLevel) { - this->particleBasicLevel = particleBasicLevel; - this->isParticleBasicLevel = true; + this->particleBasicLevel = particleBasicLevel; + this->isParticleBasicLevel = true; } void ConfigDataImp::setParticleInitLevel(int particleInitLevel) { - this->particleInitLevel = particleInitLevel; - this->isParticleInitLevel = true; + this->particleInitLevel = particleInitLevel; + this->isParticleInitLevel = true; } void ConfigDataImp::setNumberOfParticles(int numberOfParticles) { - this->numberOfParticles = numberOfParticles; - this->isNumberOfParticles = true; + this->numberOfParticles = numberOfParticles; + this->isNumberOfParticles = true; } void ConfigDataImp::setStartXHotWall(real startXHotWall) { - this->startXHotWall = startXHotWall; - this->isStartXHotWall = true; + this->startXHotWall = startXHotWall; + this->isStartXHotWall = true; } void ConfigDataImp::setEndXHotWall(real endXHotWall) { - this->endXHotWall = endXHotWall; - this->isEndXHotWall = true; + this->endXHotWall = endXHotWall; + this->isEndXHotWall = true; } void ConfigDataImp::setPossNeighborFilesX(std::vector<std::string> possNeighborFilesX) { - this->possNeighborFilesX = possNeighborFilesX; - this->isPossNeighborFilesX = true; + this->possNeighborFilesX = possNeighborFilesX; + this->isPossNeighborFilesX = true; } void ConfigDataImp::setPossNeighborFilesY(std::vector<std::string> possNeighborFilesY) { - this->possNeighborFilesY = possNeighborFilesY; - this->isPossNeighborFilesY = true; + this->possNeighborFilesY = possNeighborFilesY; + this->isPossNeighborFilesY = true; } void ConfigDataImp::setPossNeighborFilesZ(std::vector<std::string> possNeighborFilesZ) { - this->possNeighborFilesZ = possNeighborFilesZ; - this->isPossNeighborFilesZ = true; + this->possNeighborFilesZ = possNeighborFilesZ; + this->isPossNeighborFilesZ = true; } void ConfigDataImp::setTimeDoCheckPoint(int timeDoCheckPoint) { - this->timeDoCheckPoint = timeDoCheckPoint; - this->isTimeDoCheckPoint = true; + this->timeDoCheckPoint = timeDoCheckPoint; + this->isTimeDoCheckPoint = true; } void ConfigDataImp::setTimeDoRestart(int timeDoRestart) { - this->timeDoRestart = timeDoRestart; - this->isTimeDoRestart = true; + this->timeDoRestart = timeDoRestart; + this->isTimeDoRestart = true; } void ConfigDataImp::setDoCheckPoint(bool doCheckPoint) { - this->doCheckPoint = doCheckPoint; - this->isDoCheckPoint = true; + this->doCheckPoint = doCheckPoint; + this->isDoCheckPoint = true; } void ConfigDataImp::setDoRestart(bool doRestart) { - this->doRestart = doRestart; - this->isDoRestart = true; + this->doRestart = doRestart; + this->isDoRestart = true; } void ConfigDataImp::setMaxLevel(uint maxLevel) { - this->maxLevel = maxLevel; - this->isMaxLevel = true; + this->maxLevel = maxLevel; + this->isMaxLevel = true; } void ConfigDataImp::setGridX(std::vector<int> gridX) { - this->gridX = gridX; - this->isGridX = true; + this->gridX = gridX; + this->isGridX = true; } void ConfigDataImp::setGridY(std::vector<int> gridY) { - this->gridY = gridY; - this->isGridY = true; + this->gridY = gridY; + this->isGridY = true; } void ConfigDataImp::setGridZ(std::vector<int> gridZ) { - this->gridZ = gridZ; - this->isGridZ = true; + this->gridZ = gridZ; + this->isGridZ = true; } void ConfigDataImp::setDistX(std::vector<int> distX) { - this->distX = distX; - this->isDistX = true; + this->distX = distX; + this->isDistX = true; } void ConfigDataImp::setDistY(std::vector<int> distY) { - this->distY = distY; - this->isDistY = true; + this->distY = distY; + this->isDistY = true; } void ConfigDataImp::setDistZ(std::vector<int> distZ) { - this->distZ = distZ; - this->isDistZ = true; + this->distZ = distZ; + this->isDistZ = true; } void ConfigDataImp::setNeedInterface(std::vector<bool> needInterface) { - this->needInterface = needInterface; - this->isNeedInterface = true; + this->needInterface = needInterface; + this->isNeedInterface = true; } void ConfigDataImp::setMainKernel(std::string mainKernel) { - this->mainKernel = mainKernel; - this->isMainKernel = true; + this->mainKernel = mainKernel; + this->isMainKernel = true; } void ConfigDataImp::setMultiKernelOn(bool multiKernelOn) { - this->multiKernelOn = multiKernelOn; - this->isMultiKernelOn = true; + this->multiKernelOn = multiKernelOn; + this->isMultiKernelOn = true; } void ConfigDataImp::setMultiKernelLevel(std::vector<int> multiKernelLevel) { - this->multiKernelLevel = multiKernelLevel; - this->isMultiKernelLevel = true; + this->multiKernelLevel = multiKernelLevel; + this->isMultiKernelLevel = true; } void ConfigDataImp::setMultiKernelName(std::vector<std::string> multiKernelName) { - this->multiKernelName = multiKernelName; - this->isMultiKernelName = true; -} - -bool ConfigDataImp::isCalc2ndOrderMomentsInConfigFile() -{ - return this->isCalc2ndOrderMoments; + this->multiKernelName = multiKernelName; + this->isMultiKernelName = true; } -bool ConfigDataImp::isCalc3rdOrderMomentsInConfigFile() -{ - return this->isCalc2ndOrderMoments; -} +bool ConfigDataImp::isCalc2ndOrderMomentsInConfigFile() { return this->isCalc2ndOrderMoments; } -bool ConfigDataImp::isCalcHighOrderMomentsInConfigFile() -{ - return this->isCalcHighOrderMoments; -} +bool ConfigDataImp::isCalc3rdOrderMomentsInConfigFile() { return this->isCalc2ndOrderMoments; } -bool ConfigDataImp::isReadGeoInConfigFile() -{ - return this->isReadGeo; -} +bool ConfigDataImp::isCalcHighOrderMomentsInConfigFile() { return this->isCalcHighOrderMoments; } -bool ConfigDataImp::isCalcMedianInConfigFile() -{ - return this->isCalcMedian; -} +bool ConfigDataImp::isReadGeoInConfigFile() { return this->isReadGeo; } -bool ConfigDataImp::isCalcDragLiftInConfigFile() -{ - return this->isCalcDragLift; -} +bool ConfigDataImp::isCalcMedianInConfigFile() { return this->isCalcMedian; } -bool ConfigDataImp::isCalcCpInConfigFile() -{ - return this->isCalcCp; -} +bool ConfigDataImp::isCalcDragLiftInConfigFile() { return this->isCalcDragLift; } -bool ConfigDataImp::isWriteVeloASCIIfilesInConfigFile() -{ - return this->isWriteVeloASCII; -} +bool ConfigDataImp::isCalcCpInConfigFile() { return this->isCalcCp; } -bool ConfigDataImp::isCalcPlaneConcInConfigFile() -{ - return this->isCalcPlaneConc; -} +bool ConfigDataImp::isWriteVeloASCIIfilesInConfigFile() { return this->isWriteVeloASCII; } -bool ConfigDataImp::isConcFileInConfigFile() -{ - return this->isConcFile; -} +bool ConfigDataImp::isCalcPlaneConcInConfigFile() { return this->isCalcPlaneConc; } -bool ConfigDataImp::isStreetVelocityFileInConfigFile() -{ - return this->isStreetVelocityFile; -} +bool ConfigDataImp::isConcFileInConfigFile() { return this->isConcFile; } -bool ConfigDataImp::isUseMeasurePointsInConfigFile() -{ - return this->isUseMeasurePoints; -} +bool ConfigDataImp::isStreetVelocityFileInConfigFile() { return this->isStreetVelocityFile; } -bool ConfigDataImp::isUseWaleInConfigFile() -{ - return this->isUseWale; -} +bool ConfigDataImp::isUseMeasurePointsInConfigFile() { return this->isUseMeasurePoints; } -bool ConfigDataImp::isUseInitNeqInConfigFile() -{ - return this->isUseInitNeq; -} +bool ConfigDataImp::isUseWaleInConfigFile() { return this->isUseWale; } -bool ConfigDataImp::isSimulatePorousMediaInConfigFile() -{ - return this->isSimulatePorousMedia; -} +bool ConfigDataImp::isUseInitNeqInConfigFile() { return this->isUseInitNeq; } -bool ConfigDataImp::isD3QxxInConfigFile() -{ - return this->isD3Qxx; -} +bool ConfigDataImp::isSimulatePorousMediaInConfigFile() { return this->isSimulatePorousMedia; } -bool ConfigDataImp::isTEndInConfigFile() -{ - return this->isTEnd; -} +bool ConfigDataImp::isD3QxxInConfigFile() { return this->isD3Qxx; } -bool ConfigDataImp::isTOutInConfigFile() -{ - return this->isTOut; -} +bool ConfigDataImp::isTEndInConfigFile() { return this->isTEnd; } -bool ConfigDataImp::isTStartOutInConfigFile() -{ - return this->isTStartOut; -} +bool ConfigDataImp::isTOutInConfigFile() { return this->isTOut; } -bool ConfigDataImp::isTimeCalcMedStartInConfigFile() -{ - return this->isTimeCalcMedStart; -} +bool ConfigDataImp::isTStartOutInConfigFile() { return this->isTStartOut; } -bool ConfigDataImp::isTimeCalcMedEndInConfigFile() -{ - return this->isTimeCalcMedEnd; -} +bool ConfigDataImp::isTimeCalcMedStartInConfigFile() { return this->isTimeCalcMedStart; } -bool ConfigDataImp::isPressInIDInConfigFile() -{ - return this->isPressInID; -} +bool ConfigDataImp::isTimeCalcMedEndInConfigFile() { return this->isTimeCalcMedEnd; } -bool ConfigDataImp::isPressOutIDInConfigFile() -{ - return this->isPressOutID; -} +bool ConfigDataImp::isPressInIDInConfigFile() { return this->isPressInID; } -bool ConfigDataImp::isPressInZInConfigFile() -{ - return this->isPressInZ; -} +bool ConfigDataImp::isPressOutIDInConfigFile() { return this->isPressOutID; } -bool ConfigDataImp::isPressOutZInConfigFile() -{ - return this->isPressOutZ; -} +bool ConfigDataImp::isPressInZInConfigFile() { return this->isPressInZ; } -bool ConfigDataImp::isDiffOnInConfigFile() -{ - return this->isDiffOn; -} +bool ConfigDataImp::isPressOutZInConfigFile() { return this->isPressOutZ; } -bool ConfigDataImp::isDiffModInConfigFile() -{ - return this->isDiffMod; -} +bool ConfigDataImp::isDiffOnInConfigFile() { return this->isDiffOn; } -bool ConfigDataImp::isDiffusivityInConfigFile() -{ - return this->isDiffusivity; -} +bool ConfigDataImp::isDiffModInConfigFile() { return this->isDiffMod; } -bool ConfigDataImp::isTemperatureInitInConfigFile() -{ - return this->isTemperatureInit; -} +bool ConfigDataImp::isDiffusivityInConfigFile() { return this->isDiffusivity; } -bool ConfigDataImp::isTemperatureBCInConfigFile() -{ - return this->isTemperatureBC; -} +bool ConfigDataImp::isTemperatureInitInConfigFile() { return this->isTemperatureInit; } -bool ConfigDataImp::isViscosityInConfigFile() -{ - return this->isViscosity; -} +bool ConfigDataImp::isTemperatureBCInConfigFile() { return this->isTemperatureBC; } -bool ConfigDataImp::isNumberOfDevicesInConfigFile() -{ - return this->isNumberOfDevices; -} +bool ConfigDataImp::isViscosityInConfigFile() { return this->isViscosity; } -bool ConfigDataImp::isDevicesInConfigFile() -{ - return this->isDevices; -} +bool ConfigDataImp::isNumberOfDevicesInConfigFile() { return this->isNumberOfDevices; } -bool ConfigDataImp::isOutputPathInConfigFile() -{ - return this->isOutputPath; -} +bool ConfigDataImp::isDevicesInConfigFile() { return this->isDevices; } -bool ConfigDataImp::isPrefixInConfigFile() -{ - return this->isPrefix; -} +bool ConfigDataImp::isOutputPathInConfigFile() { return this->isOutputPath; } -bool ConfigDataImp::isGridPathInConfigFile() -{ - return this->isGridPath; -} +bool ConfigDataImp::isPrefixInConfigFile() { return this->isPrefix; } -bool ConfigDataImp::isPrintOutputFilesInConfigFile() -{ - return this->isPrintOutputFiles; -} +bool ConfigDataImp::isGridPathInConfigFile() { return this->isGridPath; } -bool ConfigDataImp::isGeometryValuesInConfigFile() -{ - return this->isGeometryValues; -} +bool ConfigDataImp::isPrintOutputFilesInConfigFile() { return this->isPrintOutputFiles; } -bool ConfigDataImp::isVelocityInConfigFile() -{ - return this->isVelocity; -} +bool ConfigDataImp::isGeometryValuesInConfigFile() { return this->isGeometryValues; } -bool ConfigDataImp::isViscosityRatioInConfigFile() -{ - return this->isViscosityRatio; -} +bool ConfigDataImp::isVelocityInConfigFile() { return this->isVelocity; } -bool ConfigDataImp::isVelocityRatioInConfigFile() -{ - return this->isVelocityRatio; -} +bool ConfigDataImp::isViscosityRatioInConfigFile() { return this->isViscosityRatio; } -bool ConfigDataImp::isDensityRatioInConfigFile() -{ - return this->isDensityRatio; -} +bool ConfigDataImp::isVelocityRatioInConfigFile() { return this->isVelocityRatio; } -bool ConfigDataImp::isPressRatioInConfigFile() -{ - return this->isPressRatio; -} +bool ConfigDataImp::isDensityRatioInConfigFile() { return this->isDensityRatio; } -bool ConfigDataImp::isRealXInConfigFile() -{ - return this->isRealX; -} +bool ConfigDataImp::isPressRatioInConfigFile() { return this->isPressRatio; } -bool ConfigDataImp::isRealYInConfigFile() -{ - return this->isRealY; -} +bool ConfigDataImp::isRealXInConfigFile() { return this->isRealX; } -bool ConfigDataImp::isFactorPressBCInConfigFile() -{ - return this->isFactorPressBC; -} +bool ConfigDataImp::isRealYInConfigFile() { return this->isRealY; } -bool ConfigDataImp::isGeometryFileCInConfigFile() -{ - return this->isGeometryFileC; -} +bool ConfigDataImp::isFactorPressBCInConfigFile() { return this->isFactorPressBC; } -bool ConfigDataImp::isGeometryFileMInConfigFile() -{ - return this->isGeometryFileM; -} +bool ConfigDataImp::isGeometryFileCInConfigFile() { return this->isGeometryFileC; } -bool ConfigDataImp::isGeometryFileFInConfigFile() -{ - return this->isGeometryFileF; -} +bool ConfigDataImp::isGeometryFileMInConfigFile() { return this->isGeometryFileM; } -bool ConfigDataImp::isClockCycleForMPInConfigFile() -{ - return this->isClockCycleForMP; -} +bool ConfigDataImp::isGeometryFileFInConfigFile() { return this->isGeometryFileF; } -bool ConfigDataImp::isTimestepForMPInConfigFile() -{ - return this->isTimestepForMP; -} +bool ConfigDataImp::isClockCycleForMPInConfigFile() { return this->isClockCycleForMP; } -bool ConfigDataImp::isForcingXInConfigFile() -{ - return this->isForcingX; -} +bool ConfigDataImp::isTimestepForMPInConfigFile() { return this->isTimestepForMP; } -bool ConfigDataImp::isForcingYInConfigFile() -{ - return this->isForcingY; -} +bool ConfigDataImp::isForcingXInConfigFile() { return this->isForcingX; } -bool ConfigDataImp::isForcingZInConfigFile() -{ - return this->isForcingZ; -} +bool ConfigDataImp::isForcingYInConfigFile() { return this->isForcingY; } -bool ConfigDataImp::isQuadricLimiterPInConfigFile() -{ - return this->isQuadricLimiterP; -} +bool ConfigDataImp::isForcingZInConfigFile() { return this->isForcingZ; } -bool ConfigDataImp::isQuadricLimiterMInConfigFile() -{ - return this->isQuadricLimiterM; -} +bool ConfigDataImp::isQuadricLimiterPInConfigFile() { return this->isQuadricLimiterP; } -bool ConfigDataImp::isQuadricLimiterDInConfigFile() -{ - return this->isQuadricLimiterD; -} +bool ConfigDataImp::isQuadricLimiterMInConfigFile() { return this->isQuadricLimiterM; } -bool ConfigDataImp::isCalcParticlesInConfigFile() -{ - return this->isCalcParticles; -} +bool ConfigDataImp::isQuadricLimiterDInConfigFile() { return this->isQuadricLimiterD; } -bool ConfigDataImp::isParticleBasicLevelInConfigFile() -{ - return this->isParticleBasicLevel; -} +bool ConfigDataImp::isCalcParticlesInConfigFile() { return this->isCalcParticles; } -bool ConfigDataImp::isParticleInitLevelInConfigFile() -{ - return this->isParticleInitLevel; -} +bool ConfigDataImp::isParticleBasicLevelInConfigFile() { return this->isParticleBasicLevel; } -bool ConfigDataImp::isNumberOfParticlesInConfigFile() -{ - return this->isNumberOfParticles; -} +bool ConfigDataImp::isParticleInitLevelInConfigFile() { return this->isParticleInitLevel; } -bool ConfigDataImp::isNeighborWSBInConfigFile() -{ - return this->isNeighborWSB; -} +bool ConfigDataImp::isNumberOfParticlesInConfigFile() { return this->isNumberOfParticles; } -bool ConfigDataImp::isStartXHotWallInConfigFile() -{ - return this->isStartXHotWall; -} +bool ConfigDataImp::isNeighborWSBInConfigFile() { return this->isNeighborWSB; } -bool ConfigDataImp::isEndXHotWallInConfigFile() -{ - return this->isEndXHotWall; -} +bool ConfigDataImp::isStartXHotWallInConfigFile() { return this->isStartXHotWall; } -bool ConfigDataImp::isPossNeighborFilesXInConfigFile() -{ - return this->isPossNeighborFilesX; -} +bool ConfigDataImp::isEndXHotWallInConfigFile() { return this->isEndXHotWall; } -bool ConfigDataImp::isPossNeighborFilesYInConfigFile() -{ - return this->isPossNeighborFilesY; -} +bool ConfigDataImp::isPossNeighborFilesXInConfigFile() { return this->isPossNeighborFilesX; } -bool ConfigDataImp::isPossNeighborFilesZInConfigFile() -{ - return this->isPossNeighborFilesZ; -} +bool ConfigDataImp::isPossNeighborFilesYInConfigFile() { return this->isPossNeighborFilesY; } -bool ConfigDataImp::isTimeDoCheckPointInConfigFile() -{ - return this->isTimeDoCheckPoint; -} +bool ConfigDataImp::isPossNeighborFilesZInConfigFile() { return this->isPossNeighborFilesZ; } -bool ConfigDataImp::isTimeDoRestartInConfigFile() -{ - return this->isTimeDoCheckPoint; -} +bool ConfigDataImp::isTimeDoCheckPointInConfigFile() { return this->isTimeDoCheckPoint; } -bool ConfigDataImp::isDoCheckPointInConfigFile() -{ - return this->isDoCheckPoint; -} +bool ConfigDataImp::isTimeDoRestartInConfigFile() { return this->isTimeDoCheckPoint; } -bool ConfigDataImp::isDoRestartInConfigFile() -{ - return this->isDoRestart; -} +bool ConfigDataImp::isDoCheckPointInConfigFile() { return this->isDoCheckPoint; } -bool ConfigDataImp::isMaxLevelInConfigFile() -{ - return this->isMaxLevel; -} +bool ConfigDataImp::isDoRestartInConfigFile() { return this->isDoRestart; } -bool ConfigDataImp::isGridXInConfigFile() -{ - return this->isGridX; -} +bool ConfigDataImp::isMaxLevelInConfigFile() { return this->isMaxLevel; } -bool ConfigDataImp::isGridYInConfigFile() -{ - return this->isGridY; -} +bool ConfigDataImp::isGridXInConfigFile() { return this->isGridX; } -bool ConfigDataImp::isGridZInConfigFile() -{ - return this->isGridZ; -} - -bool ConfigDataImp::isDistXInConfigFile() -{ - return this->isDistX; -} +bool ConfigDataImp::isGridYInConfigFile() { return this->isGridY; } -bool ConfigDataImp::isDistYInConfigFile() -{ - return this->isDistY; -} +bool ConfigDataImp::isGridZInConfigFile() { return this->isGridZ; } -bool ConfigDataImp::isDistZInConfigFile() -{ - return this->isDistZ; -} +bool ConfigDataImp::isDistXInConfigFile() { return this->isDistX; } -bool ConfigDataImp::isNeedInterfaceInConfigFile() -{ - return this->isNeedInterface; -} +bool ConfigDataImp::isDistYInConfigFile() { return this->isDistY; } -bool ConfigDataImp::isMainKernelInConfigFile() -{ - return this->isMainKernel; -} +bool ConfigDataImp::isDistZInConfigFile() { return this->isDistZ; } -bool ConfigDataImp::isMultiKernelOnInConfigFile() -{ - return this->isMultiKernelOn; -} +bool ConfigDataImp::isNeedInterfaceInConfigFile() { return this->isNeedInterface; } -bool ConfigDataImp::isMultiKernelLevelInConfigFile() -{ - return this->isMultiKernelLevel; -} +bool ConfigDataImp::isMainKernelInConfigFile() { return this->isMainKernel; } -bool ConfigDataImp::isMultiKernelNameInConfigFile() -{ - return this->isMultiKernelName; -} +bool ConfigDataImp::isMultiKernelOnInConfigFile() { return this->isMultiKernelOn; } +bool ConfigDataImp::isMultiKernelLevelInConfigFile() { return this->isMultiKernelLevel; } +bool ConfigDataImp::isMultiKernelNameInConfigFile() { return this->isMultiKernelName; } diff --git a/src/basics/Core/Input/ConfigData/ConfigDataImp.h b/src/basics/Core/Input/ConfigData/ConfigDataImp.h index 94d503b78..34a2a95b9 100644 --- a/src/basics/Core/Input/ConfigData/ConfigDataImp.h +++ b/src/basics/Core/Input/ConfigData/ConfigDataImp.h @@ -6,444 +6,442 @@ #include <memory> #include <string> -class ConfigDataImp : public ConfigData +class ConfigDataImp : public ConfigData { public: static std::shared_ptr<ConfigDataImp> getNewInstance(); - real getViscosity() override; - uint getNumberOfDevices() override; - std::vector<uint> getDevices() override; - std::string getOutputPath() override; - std::string getPrefix() override; - std::string getGridPath() override; - bool getPrintOutputFiles() override; - bool getGeometryValues() override; - bool getCalc2ndOrderMoments() override; - bool getCalc3rdOrderMoments() override; - bool getCalcHighOrderMoments() override; - bool getReadGeo() override; - bool getCalcMedian() override; - bool getCalcDragLift() override; - bool getCalcCp() override; - bool getWriteVeloASCIIfiles() override; - bool getCalcPlaneConc() override; - bool getConcFile() override; - bool getStreetVelocityFile() override; - bool getUseMeasurePoints() override; - bool getUseWale() override; - bool getUseInitNeq() override; - bool getSimulatePorousMedia() override; - uint getD3Qxx() override; - uint getTEnd() override; - uint getTOut() override; - uint getTStartOut() override; - uint getTimeCalcMedStart() override; - uint getTimeCalcMedEnd() override; - uint getPressInID() override; - uint getPressOutID() override; - uint getPressInZ() override; - uint getPressOutZ() override; - bool getDiffOn() override; - uint getDiffMod() override; - real getDiffusivity() override; - real getTemperatureInit() override; - real getTemperatureBC() override; - real getVelocity() override; - real getViscosityRatio() override; - real getVelocityRatio() override; - real getDensityRatio() override; - real getPressRatio() override; - real getRealX() override; - real getRealY() override; - real getFactorPressBC() override; - std::string getGeometryFileC() override; - std::string getGeometryFileM() override; - std::string getGeometryFileF() override; - uint getClockCycleForMP() override; - uint getTimestepForMP() override; - real getForcingX() override; - real getForcingY() override; - real getForcingZ() override; + real getViscosity() override; + uint getNumberOfDevices() override; + std::vector<uint> getDevices() override; + std::string getOutputPath() override; + std::string getPrefix() override; + std::string getGridPath() override; + bool getPrintOutputFiles() override; + bool getGeometryValues() override; + bool getCalc2ndOrderMoments() override; + bool getCalc3rdOrderMoments() override; + bool getCalcHighOrderMoments() override; + bool getReadGeo() override; + bool getCalcMedian() override; + bool getCalcDragLift() override; + bool getCalcCp() override; + bool getWriteVeloASCIIfiles() override; + bool getCalcPlaneConc() override; + bool getConcFile() override; + bool getStreetVelocityFile() override; + bool getUseMeasurePoints() override; + bool getUseWale() override; + bool getUseInitNeq() override; + bool getSimulatePorousMedia() override; + uint getD3Qxx() override; + uint getTEnd() override; + uint getTOut() override; + uint getTStartOut() override; + uint getTimeCalcMedStart() override; + uint getTimeCalcMedEnd() override; + uint getPressInID() override; + uint getPressOutID() override; + uint getPressInZ() override; + uint getPressOutZ() override; + bool getDiffOn() override; + uint getDiffMod() override; + real getDiffusivity() override; + real getTemperatureInit() override; + real getTemperatureBC() override; + real getVelocity() override; + real getViscosityRatio() override; + real getVelocityRatio() override; + real getDensityRatio() override; + real getPressRatio() override; + real getRealX() override; + real getRealY() override; + real getFactorPressBC() override; + std::string getGeometryFileC() override; + std::string getGeometryFileM() override; + std::string getGeometryFileF() override; + uint getClockCycleForMP() override; + uint getTimestepForMP() override; + real getForcingX() override; + real getForcingY() override; + real getForcingZ() override; real getQuadricLimiterP() override; real getQuadricLimiterM() override; real getQuadricLimiterD() override; - bool getCalcParticles() override; - int getParticleBasicLevel() override; - int getParticleInitLevel() override; - int getNumberOfParticles() override; - real getStartXHotWall() override; - real getEndXHotWall() override; - std::vector<std::string> getPossNeighborFilesX() override; - std::vector<std::string> getPossNeighborFilesY() override; - std::vector<std::string> getPossNeighborFilesZ() override; - //std::vector<std::string> getPossNeighborFilesX(); - //std::vector<std::string> getPossNeighborFilesY(); - //std::vector<std::string> getPossNeighborFilesZ(); - int getTimeDoCheckPoint() override; - int getTimeDoRestart() override; - bool getDoCheckPoint() override; - bool getDoRestart() override; - uint getMaxLevel() override; - std::vector<int> getGridX() override; - std::vector<int> getGridY() override; - std::vector<int> getGridZ() override; - std::vector<int> getDistX() override; - std::vector<int> getDistY() override; - std::vector<int> getDistZ() override; - std::vector<bool> getNeedInterface() override; - std::string getMainKernel() override; - bool getMultiKernelOn() override; - std::vector<int> getMultiKernelLevel() override; - std::vector<std::string> getMultiKernelName() override; + bool getCalcParticles() override; + int getParticleBasicLevel() override; + int getParticleInitLevel() override; + int getNumberOfParticles() override; + real getStartXHotWall() override; + real getEndXHotWall() override; + std::vector<std::string> getPossNeighborFilesX() override; + std::vector<std::string> getPossNeighborFilesY() override; + std::vector<std::string> getPossNeighborFilesZ() override; + // std::vector<std::string> getPossNeighborFilesX(); + // std::vector<std::string> getPossNeighborFilesY(); + // std::vector<std::string> getPossNeighborFilesZ(); + int getTimeDoCheckPoint() override; + int getTimeDoRestart() override; + bool getDoCheckPoint() override; + bool getDoRestart() override; + uint getMaxLevel() override; + std::vector<int> getGridX() override; + std::vector<int> getGridY() override; + std::vector<int> getGridZ() override; + std::vector<int> getDistX() override; + std::vector<int> getDistY() override; + std::vector<int> getDistZ() override; + std::vector<bool> getNeedInterface() override; + std::string getMainKernel() override; + bool getMultiKernelOn() override; + std::vector<int> getMultiKernelLevel() override; + std::vector<std::string> getMultiKernelName() override; - void setViscosity(real viscosity); - void setNumberOfDevices(uint numberOfDevices); - void setDevices(std::vector<uint> devices); - void setOutputPath(std::string outputPath); - void setPrefix(std::string prefix); - void setGridPath(std::string gridPath); - void setPrintOutputFiles(bool printOutputFiles); - void setGeometryValues(bool geometryValues); - void setCalc2ndOrderMoments(bool calc2ndOrderMoments); - void setCalc3rdOrderMoments(bool calc3rdOrderMoments); - void setCalcHighOrderMoments(bool calcHighOrderMoment); - void setReadGeo(bool readGeo); - void setCalcMedian(bool calcMedian); - void setCalcDragLift(bool calcDragLift); - void setCalcCp(bool calcCp); - void setWriteVeloASCIIfiles(bool writeVeloASCIIfiles); - void setCalcPlaneConc(bool calcPlaneConc); - void setConcFile(bool concFile); - void setStreetVelocityFile(bool streetVelocityFile); - void setUseMeasurePoints(bool useMeasurePoints); - void setUseWale(bool useWale); - void setUseInitNeq(bool useInitNeq); - void setSimulatePorousMedia(bool simulatePorousMedia); - void setD3Qxx(uint d3Qxx); - void setTEnd(uint tEnd); - void setTOut(uint tOut); - void setTStartOut(uint tStartOut); - void setTimeCalcMedStart(uint timeCalcMedStart); - void setTimeCalcMedEnd(uint timeCalcMedEnd); - void setPressInID(uint pressInID); - void setPressOutID(uint pressOutID); - void setPressInZ(uint pressInZ); - void setPressOutZ(uint pressOutZ); - void setDiffOn(bool diffOn); - void setDiffMod(uint diffMod); - void setDiffusivity(real diffusivity); - void setTemperatureInit(real temperatureInit); - void setTemperatureBC(real temperatureBC); - //void setViscosity(real viscosity); - void setVelocity(real velocity); - void setViscosityRatio(real viscosityRatio); - void setVelocityRatio(real velocityRatio); - void setDensityRatio(real fensityRatio); - void setPressRatio(real pressRatio); - void setRealX(real realX); - void setRealY(real realY); - void setFactorPressBC(real factorPressBC); - void setGeometryFileC(std::string geometryFileC); - void setGeometryFileM(std::string geometryFileM); - void setGeometryFileF(std::string geometryFileF); - void setClockCycleForMP(uint clockCycleForMP); - void setTimestepForMP(uint timestepForMP); - void setForcingX(real forcingX); - void setForcingY(real forcingY); - void setForcingZ(real forcingZ); - void setQuadricLimiterP(real quadricLimiterP); - void setQuadricLimiterM(real quadricLimiterM); - void setQuadricLimiterD(real quadricLimiterD); - void setCalcParticles(bool calcParticles); - void setParticleBasicLevel(int particleBasicLevel); - void setParticleInitLevel(int particleInitLevel); - void setNumberOfParticles(int numberOfParticles); - void setStartXHotWall(real startXHotWall); - void setEndXHotWall(real endXHotWall); - void setPossNeighborFilesX(std::vector<std::string> possNeighborFilesX); - void setPossNeighborFilesY(std::vector<std::string> possNeighborFilesY); - void setPossNeighborFilesZ(std::vector<std::string> possNeighborFilesZ); - //void setPossNeighborFilesX(std::vector<std::string> possNeighborFilesX); - //void setPossNeighborFilesY(std::vector<std::string> possNeighborFilesY); - //void setPossNeighborFilesZ(std::vector<std::string> possNeighborFilesZ); - void setTimeDoCheckPoint(int timeDoCheckPoint); - void setTimeDoRestart(int timeDoRestart); - void setDoCheckPoint(bool doCheckPoint); - void setDoRestart(bool doRestart); - void setMaxLevel(uint maxLevel); - void setGridX(std::vector<int> gridX); - void setGridY(std::vector<int> gridY); - void setGridZ(std::vector<int> gridZ); - void setDistX(std::vector<int> distX); - void setDistY(std::vector<int> distY); - void setDistZ(std::vector<int> distZ); - void setNeedInterface(std::vector<bool> needInterface); - void setMainKernel(std::string mainKernel); - void setMultiKernelOn(bool multiKernelOn); - void setMultiKernelLevel(std::vector<int> multiKernelLevel); - void setMultiKernelName(std::vector<std::string> multiKernelName); - - bool isViscosityInConfigFile() override; - bool isNumberOfDevicesInConfigFile() override; - bool isDevicesInConfigFile() override; - bool isOutputPathInConfigFile() override; - bool isPrefixInConfigFile() override; - bool isGridPathInConfigFile() override; - bool isPrintOutputFilesInConfigFile() override; - bool isGeometryValuesInConfigFile() override; - bool isCalc2ndOrderMomentsInConfigFile() override; - bool isCalc3rdOrderMomentsInConfigFile() override; - bool isCalcHighOrderMomentsInConfigFile() override; - bool isReadGeoInConfigFile() override; - bool isCalcMedianInConfigFile() override; - bool isCalcDragLiftInConfigFile() override; - bool isCalcCpInConfigFile() override; - bool isWriteVeloASCIIfilesInConfigFile() override; - bool isCalcPlaneConcInConfigFile() override; - bool isConcFileInConfigFile() override; - bool isStreetVelocityFileInConfigFile() override; - bool isUseMeasurePointsInConfigFile() override; - bool isUseWaleInConfigFile() override; - bool isUseInitNeqInConfigFile() override; - bool isSimulatePorousMediaInConfigFile() override; - bool isD3QxxInConfigFile() override; - bool isTEndInConfigFile() override; - bool isTOutInConfigFile() override; - bool isTStartOutInConfigFile() override; - bool isTimeCalcMedStartInConfigFile() override; - bool isTimeCalcMedEndInConfigFile() override; - bool isPressInIDInConfigFile() override; - bool isPressOutIDInConfigFile() override; - bool isPressInZInConfigFile() override; - bool isPressOutZInConfigFile() override; - bool isDiffOnInConfigFile() override; - bool isDiffModInConfigFile() override; - bool isDiffusivityInConfigFile() override; - bool isTemperatureInitInConfigFile() override; - bool isTemperatureBCInConfigFile() override; - //bool isViscosityInConfigFile(); - bool isVelocityInConfigFile() override; - bool isViscosityRatioInConfigFile() override; - bool isVelocityRatioInConfigFile() override; - bool isDensityRatioInConfigFile() override; - bool isPressRatioInConfigFile() override; - bool isRealXInConfigFile() override; - bool isRealYInConfigFile() override; - bool isFactorPressBCInConfigFile() override; - bool isGeometryFileCInConfigFile() override; - bool isGeometryFileMInConfigFile() override; - bool isGeometryFileFInConfigFile() override; - bool isClockCycleForMPInConfigFile() override; - bool isTimestepForMPInConfigFile() override; - bool isForcingXInConfigFile() override; - bool isForcingYInConfigFile() override; - bool isForcingZInConfigFile() override; - bool isQuadricLimiterPInConfigFile() override; - bool isQuadricLimiterMInConfigFile() override; - bool isQuadricLimiterDInConfigFile() override; - bool isCalcParticlesInConfigFile() override; - bool isParticleBasicLevelInConfigFile() override; - bool isParticleInitLevelInConfigFile() override; - bool isNumberOfParticlesInConfigFile() override; - bool isNeighborWSBInConfigFile() override; - bool isStartXHotWallInConfigFile() override; - bool isEndXHotWallInConfigFile() override; - bool isPossNeighborFilesXInConfigFile() override; - bool isPossNeighborFilesYInConfigFile() override; - bool isPossNeighborFilesZInConfigFile() override; - bool isTimeDoCheckPointInConfigFile() override; - bool isTimeDoRestartInConfigFile() override; - bool isDoCheckPointInConfigFile() override; - bool isDoRestartInConfigFile() override; - bool isMaxLevelInConfigFile() override; - bool isGridXInConfigFile() override; - bool isGridYInConfigFile() override; - bool isGridZInConfigFile() override; - bool isDistXInConfigFile() override; - bool isDistYInConfigFile() override; - bool isDistZInConfigFile() override; - bool isNeedInterfaceInConfigFile() override; - bool isMainKernelInConfigFile() override; - bool isMultiKernelOnInConfigFile() override; - bool isMultiKernelLevelInConfigFile() override; - bool isMultiKernelNameInConfigFile() override; + void setViscosity(real viscosity); + void setNumberOfDevices(uint numberOfDevices); + void setDevices(std::vector<uint> devices); + void setOutputPath(std::string outputPath); + void setPrefix(std::string prefix); + void setGridPath(std::string gridPath); + void setPrintOutputFiles(bool printOutputFiles); + void setGeometryValues(bool geometryValues); + void setCalc2ndOrderMoments(bool calc2ndOrderMoments); + void setCalc3rdOrderMoments(bool calc3rdOrderMoments); + void setCalcHighOrderMoments(bool calcHighOrderMoment); + void setReadGeo(bool readGeo); + void setCalcMedian(bool calcMedian); + void setCalcDragLift(bool calcDragLift); + void setCalcCp(bool calcCp); + void setWriteVeloASCIIfiles(bool writeVeloASCIIfiles); + void setCalcPlaneConc(bool calcPlaneConc); + void setConcFile(bool concFile); + void setStreetVelocityFile(bool streetVelocityFile); + void setUseMeasurePoints(bool useMeasurePoints); + void setUseWale(bool useWale); + void setUseInitNeq(bool useInitNeq); + void setSimulatePorousMedia(bool simulatePorousMedia); + void setD3Qxx(uint d3Qxx); + void setTEnd(uint tEnd); + void setTOut(uint tOut); + void setTStartOut(uint tStartOut); + void setTimeCalcMedStart(uint timeCalcMedStart); + void setTimeCalcMedEnd(uint timeCalcMedEnd); + void setPressInID(uint pressInID); + void setPressOutID(uint pressOutID); + void setPressInZ(uint pressInZ); + void setPressOutZ(uint pressOutZ); + void setDiffOn(bool diffOn); + void setDiffMod(uint diffMod); + void setDiffusivity(real diffusivity); + void setTemperatureInit(real temperatureInit); + void setTemperatureBC(real temperatureBC); + // void setViscosity(real viscosity); + void setVelocity(real velocity); + void setViscosityRatio(real viscosityRatio); + void setVelocityRatio(real velocityRatio); + void setDensityRatio(real fensityRatio); + void setPressRatio(real pressRatio); + void setRealX(real realX); + void setRealY(real realY); + void setFactorPressBC(real factorPressBC); + void setGeometryFileC(std::string geometryFileC); + void setGeometryFileM(std::string geometryFileM); + void setGeometryFileF(std::string geometryFileF); + void setClockCycleForMP(uint clockCycleForMP); + void setTimestepForMP(uint timestepForMP); + void setForcingX(real forcingX); + void setForcingY(real forcingY); + void setForcingZ(real forcingZ); + void setQuadricLimiterP(real quadricLimiterP); + void setQuadricLimiterM(real quadricLimiterM); + void setQuadricLimiterD(real quadricLimiterD); + void setCalcParticles(bool calcParticles); + void setParticleBasicLevel(int particleBasicLevel); + void setParticleInitLevel(int particleInitLevel); + void setNumberOfParticles(int numberOfParticles); + void setStartXHotWall(real startXHotWall); + void setEndXHotWall(real endXHotWall); + void setPossNeighborFilesX(std::vector<std::string> possNeighborFilesX); + void setPossNeighborFilesY(std::vector<std::string> possNeighborFilesY); + void setPossNeighborFilesZ(std::vector<std::string> possNeighborFilesZ); + // void setPossNeighborFilesX(std::vector<std::string> possNeighborFilesX); + // void setPossNeighborFilesY(std::vector<std::string> possNeighborFilesY); + // void setPossNeighborFilesZ(std::vector<std::string> possNeighborFilesZ); + void setTimeDoCheckPoint(int timeDoCheckPoint); + void setTimeDoRestart(int timeDoRestart); + void setDoCheckPoint(bool doCheckPoint); + void setDoRestart(bool doRestart); + void setMaxLevel(uint maxLevel); + void setGridX(std::vector<int> gridX); + void setGridY(std::vector<int> gridY); + void setGridZ(std::vector<int> gridZ); + void setDistX(std::vector<int> distX); + void setDistY(std::vector<int> distY); + void setDistZ(std::vector<int> distZ); + void setNeedInterface(std::vector<bool> needInterface); + void setMainKernel(std::string mainKernel); + void setMultiKernelOn(bool multiKernelOn); + void setMultiKernelLevel(std::vector<int> multiKernelLevel); + void setMultiKernelName(std::vector<std::string> multiKernelName); + bool isViscosityInConfigFile() override; + bool isNumberOfDevicesInConfigFile() override; + bool isDevicesInConfigFile() override; + bool isOutputPathInConfigFile() override; + bool isPrefixInConfigFile() override; + bool isGridPathInConfigFile() override; + bool isPrintOutputFilesInConfigFile() override; + bool isGeometryValuesInConfigFile() override; + bool isCalc2ndOrderMomentsInConfigFile() override; + bool isCalc3rdOrderMomentsInConfigFile() override; + bool isCalcHighOrderMomentsInConfigFile() override; + bool isReadGeoInConfigFile() override; + bool isCalcMedianInConfigFile() override; + bool isCalcDragLiftInConfigFile() override; + bool isCalcCpInConfigFile() override; + bool isWriteVeloASCIIfilesInConfigFile() override; + bool isCalcPlaneConcInConfigFile() override; + bool isConcFileInConfigFile() override; + bool isStreetVelocityFileInConfigFile() override; + bool isUseMeasurePointsInConfigFile() override; + bool isUseWaleInConfigFile() override; + bool isUseInitNeqInConfigFile() override; + bool isSimulatePorousMediaInConfigFile() override; + bool isD3QxxInConfigFile() override; + bool isTEndInConfigFile() override; + bool isTOutInConfigFile() override; + bool isTStartOutInConfigFile() override; + bool isTimeCalcMedStartInConfigFile() override; + bool isTimeCalcMedEndInConfigFile() override; + bool isPressInIDInConfigFile() override; + bool isPressOutIDInConfigFile() override; + bool isPressInZInConfigFile() override; + bool isPressOutZInConfigFile() override; + bool isDiffOnInConfigFile() override; + bool isDiffModInConfigFile() override; + bool isDiffusivityInConfigFile() override; + bool isTemperatureInitInConfigFile() override; + bool isTemperatureBCInConfigFile() override; + // bool isViscosityInConfigFile(); + bool isVelocityInConfigFile() override; + bool isViscosityRatioInConfigFile() override; + bool isVelocityRatioInConfigFile() override; + bool isDensityRatioInConfigFile() override; + bool isPressRatioInConfigFile() override; + bool isRealXInConfigFile() override; + bool isRealYInConfigFile() override; + bool isFactorPressBCInConfigFile() override; + bool isGeometryFileCInConfigFile() override; + bool isGeometryFileMInConfigFile() override; + bool isGeometryFileFInConfigFile() override; + bool isClockCycleForMPInConfigFile() override; + bool isTimestepForMPInConfigFile() override; + bool isForcingXInConfigFile() override; + bool isForcingYInConfigFile() override; + bool isForcingZInConfigFile() override; + bool isQuadricLimiterPInConfigFile() override; + bool isQuadricLimiterMInConfigFile() override; + bool isQuadricLimiterDInConfigFile() override; + bool isCalcParticlesInConfigFile() override; + bool isParticleBasicLevelInConfigFile() override; + bool isParticleInitLevelInConfigFile() override; + bool isNumberOfParticlesInConfigFile() override; + bool isNeighborWSBInConfigFile() override; + bool isStartXHotWallInConfigFile() override; + bool isEndXHotWallInConfigFile() override; + bool isPossNeighborFilesXInConfigFile() override; + bool isPossNeighborFilesYInConfigFile() override; + bool isPossNeighborFilesZInConfigFile() override; + bool isTimeDoCheckPointInConfigFile() override; + bool isTimeDoRestartInConfigFile() override; + bool isDoCheckPointInConfigFile() override; + bool isDoRestartInConfigFile() override; + bool isMaxLevelInConfigFile() override; + bool isGridXInConfigFile() override; + bool isGridYInConfigFile() override; + bool isGridZInConfigFile() override; + bool isDistXInConfigFile() override; + bool isDistYInConfigFile() override; + bool isDistZInConfigFile() override; + bool isNeedInterfaceInConfigFile() override; + bool isMainKernelInConfigFile() override; + bool isMultiKernelOnInConfigFile() override; + bool isMultiKernelLevelInConfigFile() override; + bool isMultiKernelNameInConfigFile() override; private: - ConfigDataImp(); - - real viscosity; - uint numberOfDevices; - std::vector<uint> devices; - std::string outputPath; - std::string prefix; - std::string gridPath; - bool printOutputFiles; - bool geometryValues; - bool calc2ndOrderMoments; - bool calc3rdOrderMoments; - bool calcHighOrderMoments; - bool readGeo; - bool calcMedian; - bool calcDragLift; - bool calcCp; - bool writeVeloASCIIfiles; - bool calcPlaneConc; - bool concFile; - bool streetVelocityFile; - bool useMeasurePoints; - bool useWale; - bool useInitNeq; - bool simulatePorousMedia; - uint d3Qxx; - uint tEnd; - uint tOut; - uint tStartOut; - uint timeCalcMedStart; - uint timeCalcMedEnd; - uint pressInID; - uint pressOutID; - uint pressInZ; - uint pressOutZ; - bool diffOn; - uint diffMod; - real diffusivity; - real temperatureInit; - real temperatureBC; - //real viscosity; - real velocity; - real viscosityRatio; - real velocityRatio; - real densityRatio; - real pressRatio; - real realX; - real realY; - real factorPressBC; - std::string geometryFileC; - std::string geometryFileM; - std::string geometryFileF; - uint clockCycleForMP; - uint timestepForMP; - real forcingX; - real forcingY; - real forcingZ; - real quadricLimiterP; - real quadricLimiterM; - real quadricLimiterD; - bool calcParticles; - int particleBasicLevel; - int particleInitLevel; - int numberOfParticles; - real startXHotWall; - real endXHotWall; - std::vector<std::string> possNeighborFilesX; - std::vector<std::string> possNeighborFilesY; - std::vector<std::string> possNeighborFilesZ; - //std::vector<std::string> possNeighborFilesX; - //std::vector<std::string> possNeighborFilesY; - //std::vector<std::string> possNeighborFilesZ; - int timeDoCheckPoint; - int timeDoRestart; - bool doCheckPoint; - bool doRestart; - int maxLevel; - std::vector<int> gridX; - std::vector<int> gridY; - std::vector<int> gridZ; - std::vector<int> distX; - std::vector<int> distY; - std::vector<int> distZ; - std::vector<bool> needInterface; - std::string mainKernel; - bool multiKernelOn; - std::vector<int> multiKernelLevel; - std::vector<std::string> multiKernelName; + ConfigDataImp(); - bool isViscosity; - bool isNumberOfDevices; - bool isDevices; - bool isOutputPath; - bool isPrefix; - bool isGridPath; - bool isPrintOutputFiles; - bool isGeometryValues; - bool isCalc2ndOrderMoments; - bool isCalc3rdOrderMoments; - bool isCalcHighOrderMoments; - bool isReadGeo; - bool isCalcMedian; - bool isCalcDragLift; - bool isCalcCp; - bool isWriteVeloASCII; - bool isCalcPlaneConc; - bool isConcFile; - bool isStreetVelocityFile; - bool isUseMeasurePoints; - bool isUseWale; - bool isUseInitNeq; - bool isSimulatePorousMedia; - bool isD3Qxx; - bool isTEnd; - bool isTOut; - bool isTStartOut; - bool isTimeCalcMedStart; - bool isTimeCalcMedEnd; - bool isPressInID; - bool isPressOutID; - bool isPressInZ; - bool isPressOutZ; - bool isDiffOn; - bool isDiffMod; - bool isDiffusivity; - bool isTemperatureInit; - bool isTemperatureBC; - //bool isViscosity; - bool isVelocity; - bool isViscosityRatio; - bool isVelocityRatio; - bool isDensityRatio; - bool isPressRatio; - bool isRealX; - bool isRealY; - bool isFactorPressBC; - bool isGeometryFileC; - bool isGeometryFileM; - bool isGeometryFileF; - bool isClockCycleForMP; - bool isTimestepForMP; - bool isForcingX; - bool isForcingY; - bool isForcingZ; - bool isQuadricLimiterP; - bool isQuadricLimiterM; - bool isQuadricLimiterD; - bool isCalcParticles; - bool isParticleBasicLevel; - bool isParticleInitLevel; - bool isNumberOfParticles; - bool isNeighborWSB; - bool isStartXHotWall; - bool isEndXHotWall; - bool isPossNeighborFilesX; - bool isPossNeighborFilesY; - bool isPossNeighborFilesZ; - bool isTimeDoCheckPoint; - bool isTimeDoRestart; - bool isDoCheckPoint; - bool isDoRestart; - bool isMaxLevel; - bool isGridX; - bool isGridY; - bool isGridZ; - bool isDistX; - bool isDistY; - bool isDistZ; - bool isNeedInterface; - bool isMainKernel; - bool isMultiKernelOn; - bool isMultiKernelLevel; - bool isMultiKernelName; + real viscosity; + uint numberOfDevices; + std::vector<uint> devices; + std::string outputPath; + std::string prefix; + std::string gridPath; + bool printOutputFiles; + bool geometryValues; + bool calc2ndOrderMoments; + bool calc3rdOrderMoments; + bool calcHighOrderMoments; + bool readGeo; + bool calcMedian; + bool calcDragLift; + bool calcCp; + bool writeVeloASCIIfiles; + bool calcPlaneConc; + bool concFile; + bool streetVelocityFile; + bool useMeasurePoints; + bool useWale; + bool useInitNeq; + bool simulatePorousMedia; + uint d3Qxx; + uint tEnd; + uint tOut; + uint tStartOut; + uint timeCalcMedStart; + uint timeCalcMedEnd; + uint pressInID; + uint pressOutID; + uint pressInZ; + uint pressOutZ; + bool diffOn; + uint diffMod; + real diffusivity; + real temperatureInit; + real temperatureBC; + // real viscosity; + real velocity; + real viscosityRatio; + real velocityRatio; + real densityRatio; + real pressRatio; + real realX; + real realY; + real factorPressBC; + std::string geometryFileC; + std::string geometryFileM; + std::string geometryFileF; + uint clockCycleForMP; + uint timestepForMP; + real forcingX; + real forcingY; + real forcingZ; + real quadricLimiterP; + real quadricLimiterM; + real quadricLimiterD; + bool calcParticles; + int particleBasicLevel; + int particleInitLevel; + int numberOfParticles; + real startXHotWall; + real endXHotWall; + std::vector<std::string> possNeighborFilesX; + std::vector<std::string> possNeighborFilesY; + std::vector<std::string> possNeighborFilesZ; + // std::vector<std::string> possNeighborFilesX; + // std::vector<std::string> possNeighborFilesY; + // std::vector<std::string> possNeighborFilesZ; + int timeDoCheckPoint; + int timeDoRestart; + bool doCheckPoint; + bool doRestart; + int maxLevel; + std::vector<int> gridX; + std::vector<int> gridY; + std::vector<int> gridZ; + std::vector<int> distX; + std::vector<int> distY; + std::vector<int> distZ; + std::vector<bool> needInterface; + std::string mainKernel; + bool multiKernelOn; + std::vector<int> multiKernelLevel; + std::vector<std::string> multiKernelName; + bool isViscosity; + bool isNumberOfDevices; + bool isDevices; + bool isOutputPath; + bool isPrefix; + bool isGridPath; + bool isPrintOutputFiles; + bool isGeometryValues; + bool isCalc2ndOrderMoments; + bool isCalc3rdOrderMoments; + bool isCalcHighOrderMoments; + bool isReadGeo; + bool isCalcMedian; + bool isCalcDragLift; + bool isCalcCp; + bool isWriteVeloASCII; + bool isCalcPlaneConc; + bool isConcFile; + bool isStreetVelocityFile; + bool isUseMeasurePoints; + bool isUseWale; + bool isUseInitNeq; + bool isSimulatePorousMedia; + bool isD3Qxx; + bool isTEnd; + bool isTOut; + bool isTStartOut; + bool isTimeCalcMedStart; + bool isTimeCalcMedEnd; + bool isPressInID; + bool isPressOutID; + bool isPressInZ; + bool isPressOutZ; + bool isDiffOn; + bool isDiffMod; + bool isDiffusivity; + bool isTemperatureInit; + bool isTemperatureBC; + // bool isViscosity; + bool isVelocity; + bool isViscosityRatio; + bool isVelocityRatio; + bool isDensityRatio; + bool isPressRatio; + bool isRealX; + bool isRealY; + bool isFactorPressBC; + bool isGeometryFileC; + bool isGeometryFileM; + bool isGeometryFileF; + bool isClockCycleForMP; + bool isTimestepForMP; + bool isForcingX; + bool isForcingY; + bool isForcingZ; + bool isQuadricLimiterP; + bool isQuadricLimiterM; + bool isQuadricLimiterD; + bool isCalcParticles; + bool isParticleBasicLevel; + bool isParticleInitLevel; + bool isNumberOfParticles; + bool isNeighborWSB; + bool isStartXHotWall; + bool isEndXHotWall; + bool isPossNeighborFilesX; + bool isPossNeighborFilesY; + bool isPossNeighborFilesZ; + bool isTimeDoCheckPoint; + bool isTimeDoRestart; + bool isDoCheckPoint; + bool isDoRestart; + bool isMaxLevel; + bool isGridX; + bool isGridY; + bool isGridZ; + bool isDistX; + bool isDistY; + bool isDistZ; + bool isNeedInterface; + bool isMainKernel; + bool isMultiKernelOn; + bool isMultiKernelLevel; + bool isMultiKernelName; }; #endif diff --git a/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.cpp b/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.cpp index 4bdf8669b..dce44b555 100644 --- a/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.cpp +++ b/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.cpp @@ -1,275 +1,265 @@ #include "ConfigFileReader.h" +#include "../../StringUtilities/StringUtil.h" #include "../ConfigData/ConfigDataImp.h" #include "../Input.h" -#include "../../StringUtilities/StringUtil.h" -#include <iostream> #include <fstream> - +#include <iostream> BASICS_EXPORT std::shared_ptr<ConfigFileReader> ConfigFileReader::getNewInstance() { - return std::shared_ptr<ConfigFileReader>(new ConfigFileReader()); + return std::shared_ptr<ConfigFileReader>(new ConfigFileReader()); } -ConfigFileReader::ConfigFileReader() -= default; +ConfigFileReader::ConfigFileReader() = default; -BASICS_EXPORT ConfigFileReader::~ConfigFileReader() -= default; +BASICS_EXPORT ConfigFileReader::~ConfigFileReader() = default; BASICS_EXPORT std::shared_ptr<ConfigData> ConfigFileReader::readConfigFile(const std::string &filePath) const { - std::shared_ptr<ConfigDataImp> data = ConfigDataImp::getNewInstance(); - std::ifstream stream; - stream.open(filePath.c_str(), std::ios::in); - if (stream.fail()) - throw std::runtime_error("can not open config file!"); - std::unique_ptr<input::Input> input = input::Input::makeInput(stream, "config"); - - if (input->getValue("NumberOfDevices") != "") - data->setNumberOfDevices(StringUtil::toInt(input->getValue("NumberOfDevices"))); - - if (input->getValue("Devices") != "") - data->setDevices(StringUtil::toUintVector(input->getValue("Devices"))); - - if (input->getValue("Path") != "") - data->setOutputPath(input->getValue("Path")); + std::shared_ptr<ConfigDataImp> data = ConfigDataImp::getNewInstance(); + std::ifstream stream; + stream.open(filePath.c_str(), std::ios::in); + if (stream.fail()) + throw std::runtime_error("can not open config file!"); + std::unique_ptr<input::Input> input = input::Input::makeInput(stream, "config"); - if (input->getValue("Prefix") != "") - data->setPrefix(input->getValue("Prefix")); + if (input->getValue("NumberOfDevices") != "") + data->setNumberOfDevices(StringUtil::toInt(input->getValue("NumberOfDevices"))); - if (input->getValue("GridPath") != "") - data->setGridPath(input->getValue("GridPath")); - else - { - std::cout << "GridPath has to be defined!" << std::endl; - exit(1); - } + if (input->getValue("Devices") != "") + data->setDevices(StringUtil::toUintVector(input->getValue("Devices"))); + if (input->getValue("Path") != "") + data->setOutputPath(input->getValue("Path")); - if (input->getValue("WriteGrid") != "") - data->setPrintOutputFiles(StringUtil::toBool(input->getValue("WriteGrid"))); + if (input->getValue("Prefix") != "") + data->setPrefix(input->getValue("Prefix")); - if (input->getValue("GeometryValues") != "") - data->setGeometryValues(StringUtil::toBool(input->getValue("GeometryValues"))); + if (input->getValue("GridPath") != "") + data->setGridPath(input->getValue("GridPath")); + else { + std::cout << "GridPath has to be defined!" << std::endl; + exit(1); + } - if (input->getValue("calc2ndOrderMoments") != "") - data->setCalc2ndOrderMoments(StringUtil::toBool(input->getValue("calc2ndOrderMoments"))); + if (input->getValue("WriteGrid") != "") + data->setPrintOutputFiles(StringUtil::toBool(input->getValue("WriteGrid"))); - if (input->getValue("calc3rdOrderMoments") != "") - data->setCalc3rdOrderMoments(StringUtil::toBool(input->getValue("calc3rdOrderMoments"))); + if (input->getValue("GeometryValues") != "") + data->setGeometryValues(StringUtil::toBool(input->getValue("GeometryValues"))); - if (input->getValue("calcHigherOrderMoments") != "") - data->setCalcHighOrderMoments(StringUtil::toBool(input->getValue("calcHigherOrderMoments"))); + if (input->getValue("calc2ndOrderMoments") != "") + data->setCalc2ndOrderMoments(StringUtil::toBool(input->getValue("calc2ndOrderMoments"))); - if (input->getValue("ReadGeometry") != "") - data->setReadGeo(StringUtil::toBool(input->getValue("ReadGeometry"))); + if (input->getValue("calc3rdOrderMoments") != "") + data->setCalc3rdOrderMoments(StringUtil::toBool(input->getValue("calc3rdOrderMoments"))); - if (input->getValue("calcMedian") != "") - data->setCalcMedian(StringUtil::toBool(input->getValue("calcMedian"))); + if (input->getValue("calcHigherOrderMoments") != "") + data->setCalcHighOrderMoments(StringUtil::toBool(input->getValue("calcHigherOrderMoments"))); - if (input->getValue("UseConcFile") != "") - data->setConcFile(StringUtil::toBool(input->getValue("UseConcFile"))); + if (input->getValue("ReadGeometry") != "") + data->setReadGeo(StringUtil::toBool(input->getValue("ReadGeometry"))); - if (input->getValue("UseStreetVelocityFile") != "") - data->setStreetVelocityFile(StringUtil::toBool(input->getValue("UseStreetVelocityFile"))); + if (input->getValue("calcMedian") != "") + data->setCalcMedian(StringUtil::toBool(input->getValue("calcMedian"))); - if (input->getValue("UseMeasurePoints") != "") - data->setUseMeasurePoints(StringUtil::toBool(input->getValue("UseMeasurePoints"))); + if (input->getValue("UseConcFile") != "") + data->setConcFile(StringUtil::toBool(input->getValue("UseConcFile"))); - if (input->getValue("UseWale") != "") - data->setUseWale(StringUtil::toBool(input->getValue("UseWale"))); + if (input->getValue("UseStreetVelocityFile") != "") + data->setStreetVelocityFile(StringUtil::toBool(input->getValue("UseStreetVelocityFile"))); - if (input->getValue("UseInitNeq") != "") - data->setUseInitNeq(StringUtil::toBool(input->getValue("UseInitNeq"))); + if (input->getValue("UseMeasurePoints") != "") + data->setUseMeasurePoints(StringUtil::toBool(input->getValue("UseMeasurePoints"))); - if (input->getValue("SimulatePorousMedia") != "") - data->setSimulatePorousMedia(StringUtil::toBool(input->getValue("SimulatePorousMedia"))); + if (input->getValue("UseWale") != "") + data->setUseWale(StringUtil::toBool(input->getValue("UseWale"))); - if (input->getValue("D3Qxx") != "") - data->setD3Qxx(StringUtil::toInt(input->getValue("D3Qxx"))); + if (input->getValue("UseInitNeq") != "") + data->setUseInitNeq(StringUtil::toBool(input->getValue("UseInitNeq"))); - if (input->getValue("TimeEnd") != "") - data->setTEnd(StringUtil::toInt(input->getValue("TimeEnd"))); + if (input->getValue("SimulatePorousMedia") != "") + data->setSimulatePorousMedia(StringUtil::toBool(input->getValue("SimulatePorousMedia"))); - if (input->getValue("TimeOut") != "") - data->setTOut(StringUtil::toInt(input->getValue("TimeOut"))); - - if (input->getValue("TimeStartOut") != "") - data->setTStartOut(StringUtil::toInt(input->getValue("TimeStartOut"))); + if (input->getValue("D3Qxx") != "") + data->setD3Qxx(StringUtil::toInt(input->getValue("D3Qxx"))); - if (input->getValue("TimeStartCalcMedian") != "") - data->setTimeCalcMedStart(StringUtil::toInt(input->getValue("TimeStartCalcMedian"))); + if (input->getValue("TimeEnd") != "") + data->setTEnd(StringUtil::toInt(input->getValue("TimeEnd"))); - if (input->getValue("TimeEndCalcMedian") != "") - data->setTimeCalcMedEnd(StringUtil::toInt(input->getValue("TimeEndCalcMedian"))); + if (input->getValue("TimeOut") != "") + data->setTOut(StringUtil::toInt(input->getValue("TimeOut"))); - if (input->getValue("PressInID") != "") - data->setPressInID(StringUtil::toInt(input->getValue("PressInID"))); + if (input->getValue("TimeStartOut") != "") + data->setTStartOut(StringUtil::toInt(input->getValue("TimeStartOut"))); - if (input->getValue("PressOutID") != "") - data->setPressOutID(StringUtil::toInt(input->getValue("PressOutID"))); + if (input->getValue("TimeStartCalcMedian") != "") + data->setTimeCalcMedStart(StringUtil::toInt(input->getValue("TimeStartCalcMedian"))); - if (input->getValue("PressInZ") != "") - data->setPressInZ(StringUtil::toInt(input->getValue("PressInZ"))); + if (input->getValue("TimeEndCalcMedian") != "") + data->setTimeCalcMedEnd(StringUtil::toInt(input->getValue("TimeEndCalcMedian"))); - if (input->getValue("PressOutZ") != "") - data->setPressOutZ(StringUtil::toInt(input->getValue("PressOutZ"))); - ////////////////////////////////////////////////////////////////////////// - if (input->getValue("DiffOn") != "") - data->setDiffOn(StringUtil::toBool(input->getValue("DiffOn"))); + if (input->getValue("PressInID") != "") + data->setPressInID(StringUtil::toInt(input->getValue("PressInID"))); - if (input->getValue("DiffMod") != "") - data->setDiffMod(StringUtil::toInt(input->getValue("DiffMod"))); + if (input->getValue("PressOutID") != "") + data->setPressOutID(StringUtil::toInt(input->getValue("PressOutID"))); - if (input->getValue("Diffusivity") != "") - data->setDiffusivity(StringUtil::toFloat(input->getValue("Diffusivity"))); + if (input->getValue("PressInZ") != "") + data->setPressInZ(StringUtil::toInt(input->getValue("PressInZ"))); - if (input->getValue("Temp") != "") - data->setTemperatureInit(StringUtil::toFloat(input->getValue("Temp"))); + if (input->getValue("PressOutZ") != "") + data->setPressOutZ(StringUtil::toInt(input->getValue("PressOutZ"))); + ////////////////////////////////////////////////////////////////////////// + if (input->getValue("DiffOn") != "") + data->setDiffOn(StringUtil::toBool(input->getValue("DiffOn"))); - if (input->getValue("TempBC") != "") - data->setTemperatureBC(StringUtil::toFloat(input->getValue("TempBC"))); - ////////////////////////////////////////////////////////////////////////// - if (input->getValue("Viscosity_LB") != "") - data->setViscosity(StringUtil::toFloat(input->getValue("Viscosity_LB"))); + if (input->getValue("DiffMod") != "") + data->setDiffMod(StringUtil::toInt(input->getValue("DiffMod"))); - if (input->getValue("Velocity_LB") != "") - data->setVelocity(StringUtil::toFloat(input->getValue("Velocity_LB"))); + if (input->getValue("Diffusivity") != "") + data->setDiffusivity(StringUtil::toFloat(input->getValue("Diffusivity"))); - if (input->getValue("Viscosity_Ratio_World_to_LB") != "") - data->setViscosityRatio(StringUtil::toFloat(input->getValue("Viscosity_Ratio_World_to_LB"))); + if (input->getValue("Temp") != "") + data->setTemperatureInit(StringUtil::toFloat(input->getValue("Temp"))); - if (input->getValue("Velocity_Ratio_World_to_LB") != "") - data->setVelocityRatio(StringUtil::toFloat(input->getValue("Velocity_Ratio_World_to_LB"))); + if (input->getValue("TempBC") != "") + data->setTemperatureBC(StringUtil::toFloat(input->getValue("TempBC"))); + ////////////////////////////////////////////////////////////////////////// + if (input->getValue("Viscosity_LB") != "") + data->setViscosity(StringUtil::toFloat(input->getValue("Viscosity_LB"))); - if (input->getValue("Density_Ratio_World_to_LB") != "") - data->setDensityRatio(StringUtil::toFloat(input->getValue("Density_Ratio_World_to_LB"))); + if (input->getValue("Velocity_LB") != "") + data->setVelocity(StringUtil::toFloat(input->getValue("Velocity_LB"))); - if (input->getValue("Delta_Press") != "") - data->setPressRatio(StringUtil::toFloat(input->getValue("Delta_Press"))); + if (input->getValue("Viscosity_Ratio_World_to_LB") != "") + data->setViscosityRatio(StringUtil::toFloat(input->getValue("Viscosity_Ratio_World_to_LB"))); - if (input->getValue("SliceRealX") != "") - data->setRealX(StringUtil::toFloat(input->getValue("SliceRealX"))); + if (input->getValue("Velocity_Ratio_World_to_LB") != "") + data->setVelocityRatio(StringUtil::toFloat(input->getValue("Velocity_Ratio_World_to_LB"))); - if (input->getValue("SliceRealY") != "") - data->setRealY(StringUtil::toFloat(input->getValue("SliceRealY"))); + if (input->getValue("Density_Ratio_World_to_LB") != "") + data->setDensityRatio(StringUtil::toFloat(input->getValue("Density_Ratio_World_to_LB"))); - if (input->getValue("FactorPressBC") != "") - data->setFactorPressBC(StringUtil::toFloat(input->getValue("FactorPressBC"))); + if (input->getValue("Delta_Press") != "") + data->setPressRatio(StringUtil::toFloat(input->getValue("Delta_Press"))); - if (input->getValue("GeometryC") != "") - data->setGeometryFileC(input->getValue("GeometryC")); + if (input->getValue("SliceRealX") != "") + data->setRealX(StringUtil::toFloat(input->getValue("SliceRealX"))); - if (input->getValue("GeometryM") != "") - data->setGeometryFileM(input->getValue("GeometryM")); + if (input->getValue("SliceRealY") != "") + data->setRealY(StringUtil::toFloat(input->getValue("SliceRealY"))); - if (input->getValue("GeometryF") != "") - data->setGeometryFileF(input->getValue("GeometryF")); - ////////////////////////////////////////////////////////////////////////// - if (input->getValue("measureClockCycle") != "") - data->setClockCycleForMP(StringUtil::toInt(input->getValue("measureClockCycle"))); + if (input->getValue("FactorPressBC") != "") + data->setFactorPressBC(StringUtil::toFloat(input->getValue("FactorPressBC"))); - if (input->getValue("measureTimestep") != "") - data->setTimestepForMP(StringUtil::toInt(input->getValue("measureTimestep"))); - ////////////////////////////////////////////////////////////////////////// - //Forcing - if (input->getValue("ForcingX") != "") - data->setForcingX(StringUtil::toFloat(input->getValue("ForcingX"))); - if (input->getValue("ForcingY") != "") - data->setForcingY(StringUtil::toFloat(input->getValue("ForcingY"))); - if (input->getValue("ForcingZ") != "") - data->setForcingZ(StringUtil::toFloat(input->getValue("ForcingZ"))); - ////////////////////////////////////////////////////////////////////////// - //Quadric Limiters - if (input->getValue("QuadricLimiterP") != "") - data->setQuadricLimiterP(StringUtil::toFloat(input->getValue("QuadricLimiterP"))); - if (input->getValue("QuadricLimiterM") != "") - data->setQuadricLimiterM(StringUtil::toFloat(input->getValue("QuadricLimiterM"))); - if (input->getValue("QuadricLimiterD") != "") - data->setQuadricLimiterD(StringUtil::toFloat(input->getValue("QuadricLimiterD"))); - ////////////////////////////////////////////////////////////////////////// - //Particles - if (input->getValue("calcParticles") != "") - data->setCalcParticles(StringUtil::toBool(input->getValue("calcParticles"))); + if (input->getValue("GeometryC") != "") + data->setGeometryFileC(input->getValue("GeometryC")); - if (input->getValue("baseLevel") != "") - data->setParticleBasicLevel(StringUtil::toInt(input->getValue("baseLevel"))); + if (input->getValue("GeometryM") != "") + data->setGeometryFileM(input->getValue("GeometryM")); - if (input->getValue("initLevel") != "") - data->setParticleInitLevel(StringUtil::toInt(input->getValue("initLevel"))); + if (input->getValue("GeometryF") != "") + data->setGeometryFileF(input->getValue("GeometryF")); + ////////////////////////////////////////////////////////////////////////// + if (input->getValue("measureClockCycle") != "") + data->setClockCycleForMP(StringUtil::toInt(input->getValue("measureClockCycle"))); - if (input->getValue("numberOfParticles") != "") - data->setNumberOfParticles(StringUtil::toInt(input->getValue("numberOfParticles"))); + if (input->getValue("measureTimestep") != "") + data->setTimestepForMP(StringUtil::toInt(input->getValue("measureTimestep"))); + ////////////////////////////////////////////////////////////////////////// + // Forcing + if (input->getValue("ForcingX") != "") + data->setForcingX(StringUtil::toFloat(input->getValue("ForcingX"))); + if (input->getValue("ForcingY") != "") + data->setForcingY(StringUtil::toFloat(input->getValue("ForcingY"))); + if (input->getValue("ForcingZ") != "") + data->setForcingZ(StringUtil::toFloat(input->getValue("ForcingZ"))); + ////////////////////////////////////////////////////////////////////////// + // Quadric Limiters + if (input->getValue("QuadricLimiterP") != "") + data->setQuadricLimiterP(StringUtil::toFloat(input->getValue("QuadricLimiterP"))); + if (input->getValue("QuadricLimiterM") != "") + data->setQuadricLimiterM(StringUtil::toFloat(input->getValue("QuadricLimiterM"))); + if (input->getValue("QuadricLimiterD") != "") + data->setQuadricLimiterD(StringUtil::toFloat(input->getValue("QuadricLimiterD"))); + ////////////////////////////////////////////////////////////////////////// + // Particles + if (input->getValue("calcParticles") != "") + data->setCalcParticles(StringUtil::toBool(input->getValue("calcParticles"))); - if (input->getValue("startXHotWall") != "") - data->setStartXHotWall(real(StringUtil::toDouble(input->getValue("startXHotWall")))); - - if (input->getValue("endXHotWall") != "") - data->setEndXHotWall(real(StringUtil::toDouble(input->getValue("endXHotWall")))); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //Restart - if (input->getValue("TimeDoCheckPoint") != "") - data->setTimeDoCheckPoint(StringUtil::toInt(input->getValue("TimeDoCheckPoint"))); - - if (input->getValue("TimeDoRestart") != "") - data->setTimeDoRestart(StringUtil::toInt(input->getValue("TimeDoRestart"))); - - if (input->getValue("DoCheckPoint") != "") - data->setDoCheckPoint(StringUtil::toBool(input->getValue("DoCheckPoint"))); - - if (input->getValue("DoRestart") != "") - data->setDoRestart(StringUtil::toBool(input->getValue("DoRestart"))); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - if (input->getValue("NOGL") != "") - data->setMaxLevel(StringUtil::toInt(input->getValue("NOGL"))); - - if (input->getValue("GridX") != "") - data->setGridX(StringUtil::toIntVector(input->getValue("GridX"))); - - if (input->getValue("GridY") != "") - data->setGridY(StringUtil::toIntVector(input->getValue("GridY"))); - - if (input->getValue("GridZ") != "") - data->setGridZ(StringUtil::toIntVector(input->getValue("GridZ"))); - - if (input->getValue("DistX") != "") - data->setDistX(StringUtil::toIntVector(input->getValue("DistX"))); - - if (input->getValue("DistY") != "") - data->setDistY(StringUtil::toIntVector(input->getValue("DistY"))); - - if (input->getValue("DistZ") != "") - data->setDistZ(StringUtil::toIntVector(input->getValue("DistZ"))); - - if (input->getValue("NeedInterface") != "") - data->setNeedInterface(StringUtil::toBoolVector(input->getValue("NeedInterface"))); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Kernel - if (input->getValue("MainKernelName") != "") - data->setMainKernel(input->getValue("MainKernelName")); - - if (input->getValue("MultiKernelOn") != "") - data->setMultiKernelOn(StringUtil::toBool(input->getValue("MultiKernelOn"))); - - if (input->getValue("MultiKernelLevel") != "") - data->setMultiKernelLevel(StringUtil::toIntVector(input->getValue("MultiKernelLevel"))); - - if (input->getValue("MultiKernelName") != "") - data->setMultiKernelName(StringUtil::toStringVector(input->getValue("MultiKernelName"))); - - if (StringUtil::toStringVector(input->getValue("MultiKernelName")).size() != StringUtil::toIntVector(input->getValue("MultiKernelLevel")).size()) - { - std::cout << "MultiKernelName and MultiKernelLevel has to be of same size!" << std::endl; - exit(1); - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - return data; + if (input->getValue("baseLevel") != "") + data->setParticleBasicLevel(StringUtil::toInt(input->getValue("baseLevel"))); + if (input->getValue("initLevel") != "") + data->setParticleInitLevel(StringUtil::toInt(input->getValue("initLevel"))); + + if (input->getValue("numberOfParticles") != "") + data->setNumberOfParticles(StringUtil::toInt(input->getValue("numberOfParticles"))); + + if (input->getValue("startXHotWall") != "") + data->setStartXHotWall(real(StringUtil::toDouble(input->getValue("startXHotWall")))); + + if (input->getValue("endXHotWall") != "") + data->setEndXHotWall(real(StringUtil::toDouble(input->getValue("endXHotWall")))); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Restart + if (input->getValue("TimeDoCheckPoint") != "") + data->setTimeDoCheckPoint(StringUtil::toInt(input->getValue("TimeDoCheckPoint"))); + + if (input->getValue("TimeDoRestart") != "") + data->setTimeDoRestart(StringUtil::toInt(input->getValue("TimeDoRestart"))); + + if (input->getValue("DoCheckPoint") != "") + data->setDoCheckPoint(StringUtil::toBool(input->getValue("DoCheckPoint"))); + + if (input->getValue("DoRestart") != "") + data->setDoRestart(StringUtil::toBool(input->getValue("DoRestart"))); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if (input->getValue("NOGL") != "") + data->setMaxLevel(StringUtil::toInt(input->getValue("NOGL"))); + + if (input->getValue("GridX") != "") + data->setGridX(StringUtil::toIntVector(input->getValue("GridX"))); + + if (input->getValue("GridY") != "") + data->setGridY(StringUtil::toIntVector(input->getValue("GridY"))); + + if (input->getValue("GridZ") != "") + data->setGridZ(StringUtil::toIntVector(input->getValue("GridZ"))); + + if (input->getValue("DistX") != "") + data->setDistX(StringUtil::toIntVector(input->getValue("DistX"))); + + if (input->getValue("DistY") != "") + data->setDistY(StringUtil::toIntVector(input->getValue("DistY"))); + + if (input->getValue("DistZ") != "") + data->setDistZ(StringUtil::toIntVector(input->getValue("DistZ"))); + + if (input->getValue("NeedInterface") != "") + data->setNeedInterface(StringUtil::toBoolVector(input->getValue("NeedInterface"))); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Kernel + if (input->getValue("MainKernelName") != "") + data->setMainKernel(input->getValue("MainKernelName")); + + if (input->getValue("MultiKernelOn") != "") + data->setMultiKernelOn(StringUtil::toBool(input->getValue("MultiKernelOn"))); + + if (input->getValue("MultiKernelLevel") != "") + data->setMultiKernelLevel(StringUtil::toIntVector(input->getValue("MultiKernelLevel"))); + + if (input->getValue("MultiKernelName") != "") + data->setMultiKernelName(StringUtil::toStringVector(input->getValue("MultiKernelName"))); + + if (StringUtil::toStringVector(input->getValue("MultiKernelName")).size() != + StringUtil::toIntVector(input->getValue("MultiKernelLevel")).size()) { + std::cout << "MultiKernelName and MultiKernelLevel has to be of same size!" << std::endl; + exit(1); + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + return data; } - - - - diff --git a/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.h b/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.h index 6dd241967..9d88dfce6 100644 --- a/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.h +++ b/src/basics/Core/Input/ConfigFileReader/ConfigFileReader.h @@ -7,7 +7,7 @@ class ConfigData; -class ConfigFileReader +class ConfigFileReader { public: BASICS_EXPORT static std::shared_ptr<ConfigFileReader> getNewInstance(); @@ -16,6 +16,6 @@ public: BASICS_EXPORT std::shared_ptr<ConfigData> readConfigFile(const std::string &filePath) const; private: - ConfigFileReader(); + ConfigFileReader(); }; #endif diff --git a/src/basics/Core/Input/ConfigInput/ConfigInput.cpp b/src/basics/Core/Input/ConfigInput/ConfigInput.cpp index d894bcc28..1fdff1e87 100644 --- a/src/basics/Core/Input/ConfigInput/ConfigInput.cpp +++ b/src/basics/Core/Input/ConfigInput/ConfigInput.cpp @@ -1,263 +1,222 @@ #include "ConfigInput.h" -#include <cerrno> #include <algorithm> -#include <sstream> +#include <cerrno> #include <iostream> +#include <sstream> #include <string> #define COMMENT '#' namespace input { - // Trim the given characters from the beginning and end of a string. - // the default is to trim whitespace. If the string is empty or contains - // only the trim characters, an empty string is returned. - std::string trim(const std::string &instring, const std::string &trimstring = std::string(" \t\n")) - { - if (trimstring.size() == 0) - return instring; - std::string temp = ""; - std::string::size_type begpos = instring.find_first_not_of(trimstring); - if (begpos == std::string::npos) - { - return temp; - } - else - { - std::string::size_type endpos = instring.find_last_not_of(trimstring); - temp = instring.substr(begpos, endpos - begpos + 1); - } +// Trim the given characters from the beginning and end of a string. +// the default is to trim whitespace. If the string is empty or contains +// only the trim characters, an empty string is returned. +std::string trim(const std::string &instring, const std::string &trimstring = std::string(" \t\n")) +{ + if (trimstring.size() == 0) + return instring; + std::string temp = ""; + std::string::size_type begpos = instring.find_first_not_of(trimstring); + if (begpos == std::string::npos) { return temp; + } else { + std::string::size_type endpos = instring.find_last_not_of(trimstring); + temp = instring.substr(begpos, endpos - begpos + 1); } + return temp; +} - ConfigInput::ConfigInput(std::istream &stream) : stream(stream) - { - while (!stream.eof()) - this->setTokenValuePair(); - } +ConfigInput::ConfigInput(std::istream &stream) : stream(stream) +{ + while (!stream.eof()) + this->setTokenValuePair(); +} - ConfigInput::~ConfigInput() - = default; +ConfigInput::~ConfigInput() = default; - bool ConfigInput::hasValue(const std::string &key) const - { - bool valueFound = false; - std::string keyCopy = key; - this->makeLower(keyCopy); - if (configEntries.find(keyCopy.c_str()) != configEntries.end()) - valueFound = true; +bool ConfigInput::hasValue(const std::string &key) const +{ + bool valueFound = false; + std::string keyCopy = key; + this->makeLower(keyCopy); + if (configEntries.find(keyCopy.c_str()) != configEntries.end()) + valueFound = true; - return valueFound; - } + return valueFound; +} - std::string ConfigInput::getValue(const std::string &key) - { - std::string keyCopy = key; - this->makeLower(keyCopy); - if (configEntries.find(keyCopy.c_str()) != configEntries.end()) - return (*configEntries.find(keyCopy.c_str())).second; - return ""; - } +std::string ConfigInput::getValue(const std::string &key) +{ + std::string keyCopy = key; + this->makeLower(keyCopy); + if (configEntries.find(keyCopy.c_str()) != configEntries.end()) + return (*configEntries.find(keyCopy.c_str())).second; + return ""; +} - ////////////////////////////////////////////////////////////////////////// - // private methods // - ////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +// private methods // +////////////////////////////////////////////////////////////////////////// - void ConfigInput::makeLower(std::string &value) const - { - for (size_t i = 0; i < value.size(); i++) - value[i] = tolower(value[i]); - } +void ConfigInput::makeLower(std::string &value) const +{ + for (size_t i = 0; i < value.size(); i++) + value[i] = tolower(value[i]); +} - void ConfigInput::setTokenValuePair() - { - this->eatWhiteAndComments(true); +void ConfigInput::setTokenValuePair() +{ + this->eatWhiteAndComments(true); - std::string token; - if(!this->setToken(token)) - return; + std::string token; + if (!this->setToken(token)) + return; - std::string value; - this->setValue(value); + std::string value; + this->setValue(value); - configEntries.insert(String_Pair(token, value)); - } + configEntries.insert(String_Pair(token, value)); +} - bool ConfigInput::setToken(std::string &token) - { - char tokenChar[1024]; - bool foundEqualSign = false; - int charIndex = 0; +bool ConfigInput::setToken(std::string &token) +{ + char tokenChar[1024]; + bool foundEqualSign = false; + int charIndex = 0; - this->findToken(foundEqualSign, tokenChar, charIndex); + this->findToken(foundEqualSign, tokenChar, charIndex); - if (!isToken(charIndex, foundEqualSign)) - return false; + if (!isToken(charIndex, foundEqualSign)) + return false; - this->nullTerminate(tokenChar, charIndex); - token = tokenChar; - makeLower(token); - return true; - } + this->nullTerminate(tokenChar, charIndex); + token = tokenChar; + makeLower(token); + return true; +} - void ConfigInput::findToken(bool &foundEqualSign, char *token, int &i) - { - char ch; - while (!(stream.get(ch)).fail()) - { - if ((ch != '\t')) - { - if ((ch == '=') || (ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t')) - { - foundEqualSign = true; - break; - } - token[i++] = ch; +void ConfigInput::findToken(bool &foundEqualSign, char *token, int &i) +{ + char ch; + while (!(stream.get(ch)).fail()) { + if ((ch != '\t')) { + if ((ch == '=') || (ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t')) { + foundEqualSign = true; + break; } + token[i++] = ch; } } +} - - bool ConfigInput::isToken(int charIndex, bool foundEqualSign) - { - if (charIndex == 0) - { - configEntries.insert(String_Pair("", "")); - return false; - } - - if (!foundEqualSign && !advanceToEqualSignOnLine()) - { - configEntries.insert(String_Pair("", "")); - return false; - } - return true; +bool ConfigInput::isToken(int charIndex, bool foundEqualSign) +{ + if (charIndex == 0) { + configEntries.insert(String_Pair("", "")); + return false; } - void ConfigInput::setValue(std::string &value) - { - int charIndex = 0; - char valueChar[1024]; - this->findValue(charIndex, valueChar); - - if (charIndex == 0) - value = ""; - else - { - this->nullTerminate(valueChar, charIndex); - value = valueChar; - value = trim(value); - this->stripLeadingAndTrailingQuotes(value); - } + if (!foundEqualSign && !advanceToEqualSignOnLine()) { + configEntries.insert(String_Pair("", "")); + return false; } + return true; +} +void ConfigInput::setValue(std::string &value) +{ + int charIndex = 0; + char valueChar[1024]; + this->findValue(charIndex, valueChar); + + if (charIndex == 0) + value = ""; + else { + this->nullTerminate(valueChar, charIndex); + value = valueChar; + value = trim(value); + this->stripLeadingAndTrailingQuotes(value); + } +} - int ConfigInput::findValue(int &charIndex, char * value) - { - char ch; - char c = eatWhiteAndComments(false); - if (c != '\n') - { - charIndex = 0; - while (!(stream.get(ch)).fail()) - { - if ((ch == '\t') || (ch == '\r') || (ch == '\n') || (ch == '#')) - { - while (ch != '\n') - { - if (stream.get(ch).fail()) break; - } - break; - } - else - { - value[charIndex++] = ch; +int ConfigInput::findValue(int &charIndex, char *value) +{ + char ch; + char c = eatWhiteAndComments(false); + if (c != '\n') { + charIndex = 0; + while (!(stream.get(ch)).fail()) { + if ((ch == '\t') || (ch == '\r') || (ch == '\n') || (ch == '#')) { + while (ch != '\n') { + if (stream.get(ch).fail()) + break; } + break; + } else { + value[charIndex++] = ch; } - } - return charIndex; + } } + return charIndex; +} +void ConfigInput::stripLeadingAndTrailingQuotes(std::string &m_value) +{ + if (m_value[0] == '"') + m_value = m_value.substr(1); + if (m_value[m_value.length() - 1] == '"') + m_value = m_value.substr(0, m_value.length() - 1); +} +void ConfigInput::nullTerminate(char *value, int &i) { value[i++] = '\0'; } - void ConfigInput::stripLeadingAndTrailingQuotes(std::string &m_value) - { - if (m_value[0] == '"') - m_value = m_value.substr(1); - if (m_value[m_value.length() - 1] == '"') - m_value = m_value.substr(0, m_value.length() - 1); - } - - void ConfigInput::nullTerminate(char *value, int &i) - { - value[i++] = '\0'; - } - - bool ConfigInput::advanceToEqualSignOnLine() - { - char ch; - bool foundEqual = false; - while (!(stream.get(ch)).fail()) - { - if (isNewLine(ch) || isCarriageReturn(ch)) - break; - if (isEqualSign(ch)) - { - foundEqual = true; - break; - } +bool ConfigInput::advanceToEqualSignOnLine() +{ + char ch; + bool foundEqual = false; + while (!(stream.get(ch)).fail()) { + if (isNewLine(ch) || isCarriageReturn(ch)) + break; + if (isEqualSign(ch)) { + foundEqual = true; + break; } - return foundEqual; } + return foundEqual; +} - char ConfigInput::eatWhiteAndComments(bool traverseNewlines) - { - char ch; - bool isComment = false; - - while (!(stream.get(ch)).fail()) - { - if (isCommentSign(ch)) - isComment = true; - else if (isNewLine(ch)) - { - isComment = false; - if (!traverseNewlines) - return(ch); - } - else if (isRegularChar(isComment, ch)) - { - stream.putback(ch); - return 0; - } +char ConfigInput::eatWhiteAndComments(bool traverseNewlines) +{ + char ch; + bool isComment = false; + + while (!(stream.get(ch)).fail()) { + if (isCommentSign(ch)) + isComment = true; + else if (isNewLine(ch)) { + isComment = false; + if (!traverseNewlines) + return (ch); + } else if (isRegularChar(isComment, ch)) { + stream.putback(ch); + return 0; } - return 0; - } - - bool ConfigInput::isRegularChar(bool isComment, char ch) - { - return (!isComment) && (ch != ' ') && (ch != '\t') && (ch != '\r'); } + return 0; +} - bool ConfigInput::isCommentSign(char ch) - { - return ch == COMMENT; - } +bool ConfigInput::isRegularChar(bool isComment, char ch) +{ + return (!isComment) && (ch != ' ') && (ch != '\t') && (ch != '\r'); +} - bool ConfigInput::isEqualSign(char ch) - { - return ch == '='; - } +bool ConfigInput::isCommentSign(char ch) { return ch == COMMENT; } - bool ConfigInput::isNewLine(char ch) - { - return ch == '\n'; - } +bool ConfigInput::isEqualSign(char ch) { return ch == '='; } - bool ConfigInput::isCarriageReturn(char ch) - { - return ch == '\r'; - } +bool ConfigInput::isNewLine(char ch) { return ch == '\n'; } +bool ConfigInput::isCarriageReturn(char ch) { return ch == '\r'; } -} +} // namespace input diff --git a/src/basics/Core/Input/ConfigInput/ConfigInput.h b/src/basics/Core/Input/ConfigInput/ConfigInput.h index d01e1b812..aee9242ca 100644 --- a/src/basics/Core/Input/ConfigInput/ConfigInput.h +++ b/src/basics/Core/Input/ConfigInput/ConfigInput.h @@ -1,48 +1,48 @@ #ifndef ConfigInput_H #define ConfigInput_H -#include <string> -#include <vector> #include <istream> -#include <memory> -#include <map> #include <list> +#include <map> +#include <memory> +#include <string> +#include <vector> -#include "basics_export.h" #include "../Input.h" +#include "basics_export.h" -namespace input +namespace input +{ +class ConfigInput : public Input { - class ConfigInput : public Input - { - public: - BASICS_EXPORT ConfigInput(std::istream &stream); - BASICS_EXPORT ~ConfigInput() override; - - BASICS_EXPORT bool hasValue(const std::string &key) const override; - BASICS_EXPORT std::string getValue(const std::string &key) override; +public: + BASICS_EXPORT ConfigInput(std::istream &stream); + BASICS_EXPORT ~ConfigInput() override; + + BASICS_EXPORT bool hasValue(const std::string &key) const override; + BASICS_EXPORT std::string getValue(const std::string &key) override; - protected: - virtual void setTokenValuePair(); - void setValue(std::string &value); - bool setToken(std::string &token); - bool isToken(int charIndex, bool foundEqualSign); - int findValue(int &charIndex, char * value); - void stripLeadingAndTrailingQuotes(std::string &m_value); - void nullTerminate(char * token, int &i); - void findToken(bool &foundEqualSign, char * token, int &i); - char eatWhiteAndComments(bool traverse_newlines = true); - bool isRegularChar(bool isComment, char ch); - bool isNewLine(char ch); - bool isCommentSign(char ch); - bool advanceToEqualSignOnLine(); - bool isCarriageReturn(char ch); - bool isEqualSign(char ch); - void makeLower(std::string &instring) const; +protected: + virtual void setTokenValuePair(); + void setValue(std::string &value); + bool setToken(std::string &token); + bool isToken(int charIndex, bool foundEqualSign); + int findValue(int &charIndex, char *value); + void stripLeadingAndTrailingQuotes(std::string &m_value); + void nullTerminate(char *token, int &i); + void findToken(bool &foundEqualSign, char *token, int &i); + char eatWhiteAndComments(bool traverse_newlines = true); + bool isRegularChar(bool isComment, char ch); + bool isNewLine(char ch); + bool isCommentSign(char ch); + bool advanceToEqualSignOnLine(); + bool isCarriageReturn(char ch); + bool isEqualSign(char ch); + void makeLower(std::string &instring) const; - protected: - std::istream &stream; - using String_Pair = std::pair <std::string, std::string>; - std::map<std::string, std::string> configEntries; - }; -} +protected: + std::istream &stream; + using String_Pair = std::pair<std::string, std::string>; + std::map<std::string, std::string> configEntries; +}; +} // namespace input #endif diff --git a/src/basics/Core/Input/Input.cpp b/src/basics/Core/Input/Input.cpp index 4d2aee7de..f971dd226 100644 --- a/src/basics/Core/Input/Input.cpp +++ b/src/basics/Core/Input/Input.cpp @@ -11,15 +11,14 @@ namespace input { - std::unique_ptr<input::Input> Input::makeInput(std::istream &stream, const std::string & /*inputType*/) - { +std::unique_ptr<input::Input> Input::makeInput(std::istream &stream, const std::string & /*inputType*/) +{ #ifdef BUILD_JSONCPP - if(inputType == "json") - return std::unique_ptr<Input>(new JsonInput(stream)); + if (inputType == "json") + return std::unique_ptr<Input>(new JsonInput(stream)); #endif - return std::make_unique<ConfigInput>(stream); - } - + return std::make_unique<ConfigInput>(stream); } +} // namespace input diff --git a/src/basics/Core/Input/Input.h b/src/basics/Core/Input/Input.h index 9c95e2a16..3b07b8b32 100644 --- a/src/basics/Core/Input/Input.h +++ b/src/basics/Core/Input/Input.h @@ -3,23 +3,22 @@ #include "basics_export.h" - -#include <string> -#include <memory> #include <istream> +#include <memory> +#include <string> namespace input { - class Input - { - public: - static BASICS_EXPORT std::unique_ptr<Input> makeInput(std::istream &stream, const std::string &inputType); +class Input +{ +public: + static BASICS_EXPORT std::unique_ptr<Input> makeInput(std::istream &stream, const std::string &inputType); - virtual ~Input() = default; + virtual ~Input() = default; - virtual bool hasValue(const std::string &key) const = 0; - virtual std::string getValue(const std::string &key) = 0; - }; -} + virtual bool hasValue(const std::string &key) const = 0; + virtual std::string getValue(const std::string &key) = 0; +}; +} // namespace input #endif diff --git a/src/basics/Core/Input/JsonInput/JsonInput.cpp b/src/basics/Core/Input/JsonInput/JsonInput.cpp index 9524e87ed..34a1d154a 100644 --- a/src/basics/Core/Input/JsonInput/JsonInput.cpp +++ b/src/basics/Core/Input/JsonInput/JsonInput.cpp @@ -3,64 +3,65 @@ #include "JsonInput.h" #include <fstream> -#include <string> +#include <iterator> #include <sstream> +#include <string> #include <vector> -#include <iterator> namespace input { - template<typename Out> - void split(const std::string &s, char delim, Out result) { - std::stringstream ss; - ss.str(s); - std::string item; - while (std::getline(ss, item, delim)) { - *(result++) = item; - } - } - - std::vector<std::string> split(const std::string &s, char delim) { - std::vector<std::string> elems; - split(s, delim, std::back_inserter(elems)); - return elems; - } - - JsonInput::JsonInput(std::istream &stream) - { - Json::Reader reader; - reader.parse(stream, jsonValue); +template <typename Out> +void split(const std::string &s, char delim, Out result) +{ + std::stringstream ss; + ss.str(s); + std::string item; + while (std::getline(ss, item, delim)) { + *(result++) = item; } +} - bool JsonInput::hasValue(const std::string &key) const - { - auto keys = split(key, ' '); +std::vector<std::string> split(const std::string &s, char delim) +{ + std::vector<std::string> elems; + split(s, delim, std::back_inserter(elems)); + return elems; +} - if (keys.size() == 1 && !jsonValue[keys[0]].isNull()) - return true; - else if (keys.size() == 2 && !jsonValue[keys[0]][keys[1]].isNull()) - return true; - else if (keys.size() == 3 && !jsonValue[keys[0]][keys[1]][keys[2]].isNull()) - return true; - else - return false; - } +JsonInput::JsonInput(std::istream &stream) +{ + Json::Reader reader; + reader.parse(stream, jsonValue); +} - std::string JsonInput::getValue(const std::string &key) - { - auto keys = split(key, ' '); +bool JsonInput::hasValue(const std::string &key) const +{ + auto keys = split(key, ' '); - if(keys.size() == 1) - return jsonValue[keys[0]].asString(); - else if (keys.size() == 2) - return jsonValue[keys[0]][keys[1]].asString(); - else if (keys.size() == 3) - return jsonValue[keys[0]][keys[1]][keys[2]].asString(); - else - return ""; - } + if (keys.size() == 1 && !jsonValue[keys[0]].isNull()) + return true; + else if (keys.size() == 2 && !jsonValue[keys[0]][keys[1]].isNull()) + return true; + else if (keys.size() == 3 && !jsonValue[keys[0]][keys[1]][keys[2]].isNull()) + return true; + else + return false; +} +std::string JsonInput::getValue(const std::string &key) +{ + auto keys = split(key, ' '); + if (keys.size() == 1) + return jsonValue[keys[0]].asString(); + else if (keys.size() == 2) + return jsonValue[keys[0]][keys[1]].asString(); + else if (keys.size() == 3) + return jsonValue[keys[0]][keys[1]][keys[2]].asString(); + else + return ""; } +} // namespace input + #endif diff --git a/src/basics/Core/Input/JsonInput/JsonInput.h b/src/basics/Core/Input/JsonInput/JsonInput.h index 5e1d81e68..8a33e99bf 100644 --- a/src/basics/Core/Input/JsonInput/JsonInput.h +++ b/src/basics/Core/Input/JsonInput/JsonInput.h @@ -3,31 +3,27 @@ #ifndef JsonInput_H #define JsonInput_H - -#include <string> #include <json/json.h> - +#include <string> #include "basics_export.h" - #include "../Input.h" namespace input { - class JsonInput : public Input - { - public: - BASICS_EXPORT JsonInput(std::istream &stream); - - BASICS_EXPORT virtual bool hasValue(const std::string &key) const override; - BASICS_EXPORT virtual std::string getValue(const std::string &key) override; +class JsonInput : public Input +{ +public: + BASICS_EXPORT JsonInput(std::istream &stream); - private: - Json::Value jsonValue; + BASICS_EXPORT virtual bool hasValue(const std::string &key) const override; + BASICS_EXPORT virtual std::string getValue(const std::string &key) override; - }; -} +private: + Json::Value jsonValue; +}; +} // namespace input #endif diff --git a/src/basics/Core/LbmOrGks.h b/src/basics/Core/LbmOrGks.h index 96ef76a5a..ae4a17cad 100644 --- a/src/basics/Core/LbmOrGks.h +++ b/src/basics/Core/LbmOrGks.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,10 +33,6 @@ #ifndef LBMORGKS_H #define LBMORGKS_H -enum LbmOrGks -{ - LBM, - GKS -}; +enum LbmOrGks { LBM, GKS }; #endif diff --git a/src/basics/Core/Logger/Logger.cpp b/src/basics/Core/Logger/Logger.cpp index f7a9b2a1e..6ee96cba5 100644 --- a/src/basics/Core/Logger/Logger.cpp +++ b/src/basics/Core/Logger/Logger.cpp @@ -1,86 +1,61 @@ #include "Logger.h" //#include "mpi.h" -#include <memory> #include <iostream> +#include <memory> #include "implementations/LoggerImp.h" +namespace logging +{ +std::shared_ptr<Logger> out = nullptr; -namespace logging { - - std::shared_ptr<Logger> out = nullptr; +logging::Logger::Level logging::Logger::globalLogLevel = logging::Logger::INFO_LOW; +logging::Logger::Level logging::Logger::localLogLevel = logging::Logger::INFO_LOW; +bool logging::Logger::printRankNumber = false; +bool logging::Logger::timeStampEnabled = false; - logging::Logger::Level logging::Logger::globalLogLevel = logging::Logger::INFO_LOW; - logging::Logger::Level logging::Logger::localLogLevel = logging::Logger::INFO_LOW; - bool logging::Logger::printRankNumber = false; - bool logging::Logger::timeStampEnabled = false; - +logging::Logger::Logger(std::ostream *stream) { streams.push_back(stream); } - logging::Logger::Logger(std::ostream* stream) - { - streams.push_back(stream); - } +logging::Logger::~Logger() = default; - logging::Logger::~Logger() - = default; - - void Logger::addStreamToList(std::ostream* stream) - { - streams.push_back(stream); - } - - void Logger::resetStreamList() - { - streams.clear(); - } +void Logger::addStreamToList(std::ostream *stream) { streams.push_back(stream); } +void Logger::resetStreamList() { streams.clear(); } //-----------static methods----------------// - void logging::Logger::resetStreams() - { - if (!out) - out = std::make_shared<LoggerImp>(&std::cout); +void logging::Logger::resetStreams() +{ + if (!out) + out = std::make_shared<LoggerImp>(&std::cout); - out->resetStreamList(); - } + out->resetStreamList(); +} - void logging::Logger::setStream(std::ostream* stream) - { - out = std::make_shared<LoggerImp>(stream); - } +void logging::Logger::setStream(std::ostream *stream) { out = std::make_shared<LoggerImp>(stream); } - void logging::Logger::addStream(std::ostream* stream) - { - if (!out) - out = std::make_shared<LoggerImp>(stream); - else - out->addStreamToList(stream); - } +void logging::Logger::addStream(std::ostream *stream) +{ + if (!out) + out = std::make_shared<LoggerImp>(stream); + else + out->addStreamToList(stream); +} - void logging::Logger::timeStamp(TimeStamp timeStamp) - { - switch(timeStamp) - { +void logging::Logger::timeStamp(TimeStamp timeStamp) +{ + switch (timeStamp) { case ENABLE: timeStampEnabled = true; break; case DISABLE: timeStampEnabled = false; break; - } } +} +void logging::Logger::setDebugLevel(const Level &level) { globalLogLevel = level; } +void logging::Logger::enablePrintedRankNumbers(bool print) { printRankNumber = print; } - void logging::Logger::setDebugLevel(const Level &level) - { - globalLogLevel = level; - } - - void logging::Logger::enablePrintedRankNumbers(bool print) - { - printRankNumber = print; - } - -} +} // namespace logging diff --git a/src/basics/Core/Logger/Logger.h b/src/basics/Core/Logger/Logger.h index fa8a00040..d0cd91938 100644 --- a/src/basics/Core/Logger/Logger.h +++ b/src/basics/Core/Logger/Logger.h @@ -3,68 +3,54 @@ #include "basics_export.h" -#include <string> #include <memory> #include <ostream> +#include <string> #include <vector> -namespace logging +namespace logging { - class BASICS_EXPORT Logger - { - protected: - Logger(std::ostream* stream); - - public: - virtual ~Logger(); - - enum Level - { - INFO_LOW = 3, - INFO_INTERMEDIATE = 2, - INFO_HIGH = 1, - WARNING = 0, - LOGGER_ERROR = -1 - }; - - enum TimeStamp - { - ENABLE, - DISABLE - }; +class BASICS_EXPORT Logger +{ +protected: + Logger(std::ostream *stream); - static void setStream(std::ostream* stream); - static void addStream(std::ostream* stream); - static void resetStreams(); +public: + virtual ~Logger(); - static void timeStamp(TimeStamp timeStamp); + enum Level { INFO_LOW = 3, INFO_INTERMEDIATE = 2, INFO_HIGH = 1, WARNING = 0, LOGGER_ERROR = -1 }; - static void setDebugLevel(const Level &level = Level::LOGGER_ERROR); - static void enablePrintedRankNumbers(bool printRankNumbers); + enum TimeStamp { ENABLE, DISABLE }; - virtual Logger& operator<<(const Level &level) = 0; - virtual Logger& operator<<(const std::string &log) = 0; - virtual Logger& operator<<(const int &log) = 0; - virtual Logger& operator<<(const unsigned int &log) = 0; - virtual Logger& operator<<(const unsigned long& log) = 0; - virtual Logger& operator<<(const float &log) = 0; - virtual Logger& operator<<(const double &log) = 0; + static void setStream(std::ostream *stream); + static void addStream(std::ostream *stream); + static void resetStreams(); - protected: - void addStreamToList(std::ostream* stream); - void resetStreamList(); + static void timeStamp(TimeStamp timeStamp); - std::vector<std::ostream*> streams; + static void setDebugLevel(const Level &level = Level::LOGGER_ERROR); + static void enablePrintedRankNumbers(bool printRankNumbers); - static Level globalLogLevel; - static Level localLogLevel; - static bool printRankNumber; - static bool timeStampEnabled; + virtual Logger &operator<<(const Level &level) = 0; + virtual Logger &operator<<(const std::string &log) = 0; + virtual Logger &operator<<(const int &log) = 0; + virtual Logger &operator<<(const unsigned int &log) = 0; + virtual Logger &operator<<(const unsigned long &log) = 0; + virtual Logger &operator<<(const float &log) = 0; + virtual Logger &operator<<(const double &log) = 0; - }; - extern BASICS_EXPORT std::shared_ptr<Logger> out; -} +protected: + void addStreamToList(std::ostream *stream); + void resetStreamList(); + std::vector<std::ostream *> streams; + static Level globalLogLevel; + static Level localLogLevel; + static bool printRankNumber; + static bool timeStampEnabled; +}; +extern BASICS_EXPORT std::shared_ptr<Logger> out; +} // namespace logging #endif diff --git a/src/basics/Core/Logger/implementations/LoggerImp.cpp b/src/basics/Core/Logger/implementations/LoggerImp.cpp index 48ad23a30..f002fdc59 100644 --- a/src/basics/Core/Logger/implementations/LoggerImp.cpp +++ b/src/basics/Core/Logger/implementations/LoggerImp.cpp @@ -1,68 +1,52 @@ #include "LoggerImp.h" +#include <chrono> +#include <iomanip> +#include <iostream> #include <mpi.h> #include <sstream> -#include <iostream> -#include <iomanip> -#include <chrono> - -logging::LoggerImp::LoggerImp(std::ostream* stream) : logging::Logger(stream) +logging::LoggerImp::LoggerImp(std::ostream *stream) : logging::Logger(stream) { levelString[Level::WARNING] = "[WARNING] "; - levelString[Level::LOGGER_ERROR] = "[ERROR] "; + levelString[Level::LOGGER_ERROR] = "[ERROR] "; levelString[Level::INFO_LOW] = "[INFO_LOW] "; levelString[Level::INFO_INTERMEDIATE] = "[INFO_INTERMEDIATE]"; levelString[Level::INFO_HIGH] = "[INFO_HIGH] "; } -logging::LoggerImp::~LoggerImp() -= default; +logging::LoggerImp::~LoggerImp() = default; -logging::Logger& logging::LoggerImp::operator<<(const Level &level) +logging::Logger &logging::LoggerImp::operator<<(const Level &level) { localLogLevel = level; return *this; } +logging::Logger &logging::LoggerImp::operator<<(const std::string &message) { return this->log(message); } -logging::Logger& logging::LoggerImp::operator<<(const std::string &message) -{ - return this->log(message); -} - -logging::Logger& logging::LoggerImp::operator<<(const int &message) -{ - return this->log(std::to_string(message)); -} +logging::Logger &logging::LoggerImp::operator<<(const int &message) { return this->log(std::to_string(message)); } -logging::Logger& logging::LoggerImp::operator<<(const unsigned int &message) +logging::Logger &logging::LoggerImp::operator<<(const unsigned int &message) { return this->log(std::to_string(message)); } -logging::Logger& logging::LoggerImp::operator<<(const unsigned long &message) +logging::Logger &logging::LoggerImp::operator<<(const unsigned long &message) { return this->log(std::to_string(message)); } -logging::Logger& logging::LoggerImp::operator<<(const float &message) -{ - return this->log(std::to_string(message)); -} +logging::Logger &logging::LoggerImp::operator<<(const float &message) { return this->log(std::to_string(message)); } -logging::Logger& logging::LoggerImp::operator<<(const double &message) -{ - return this->log(std::to_string(message)); -} +logging::Logger &logging::LoggerImp::operator<<(const double &message) { return this->log(std::to_string(message)); } -logging::Logger& logging::LoggerImp::log(const std::string &message) +logging::Logger &logging::LoggerImp::log(const std::string &message) { - if (shouldBeLogged()) - { + if (shouldBeLogged()) { std::string modifiedMessage = message; addDebugInformation(modifiedMessage); - for(auto stream : streams) + for (auto stream : streams) *stream << modifiedMessage << std::flush; } std::size_t found = message.find(std::string("\n")); @@ -74,43 +58,37 @@ logging::Logger& logging::LoggerImp::log(const std::string &message) return *this; } -bool logging::LoggerImp::shouldBeLogged() -{ - return localLogLevel <= globalLogLevel; -} +bool logging::LoggerImp::shouldBeLogged() { return localLogLevel <= globalLogLevel; } -void logging::LoggerImp::addDebugInformation(std::string& message) +void logging::LoggerImp::addDebugInformation(std::string &message) { if (newLoggingLine) { std::stringstream os; - os << levelString[localLogLevel] << getTimeStamp() << " " << message; + os << levelString[localLogLevel] << getTimeStamp() << " " << message; message = os.str(); } } - std::string logging::LoggerImp::getTimeStamp() { if (!timeStampEnabled) return ""; const auto now = std::chrono::system_clock::now(); - time_t tt = std::chrono::system_clock::to_time_t(now); - //const tm utc_tm = *gmtime(&tt); + time_t tt = std::chrono::system_clock::to_time_t(now); + // const tm utc_tm = *gmtime(&tt); const tm local_tm = *localtime(&tt); std::stringstream os; os << " [" << std::setw(2) << std::setfill('0') << local_tm.tm_hour << ":"; - os << std::setw(2) << std::setfill('0') << local_tm.tm_min << ":"; - os << std::setw(2) << std::setfill('0') << local_tm.tm_sec << "]"; + os << std::setw(2) << std::setfill('0') << local_tm.tm_min << ":"; + os << std::setw(2) << std::setfill('0') << local_tm.tm_sec << "]"; return os.str(); } - std::string logging::LoggerImp::getRankString() { int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); return printRankNumber ? "[" + std::to_string(rank) + "] " : ""; } - diff --git a/src/basics/Core/Logger/implementations/LoggerImp.h b/src/basics/Core/Logger/implementations/LoggerImp.h index 851f29464..45b64b6dc 100644 --- a/src/basics/Core/Logger/implementations/LoggerImp.h +++ b/src/basics/Core/Logger/implementations/LoggerImp.h @@ -1,7 +1,6 @@ #ifndef LoggerImp_H #define LoggerImp_H - #include "basics_export.h" #include <string> @@ -12,35 +11,33 @@ namespace logging { - class BASICS_EXPORT LoggerImp : public Logger - { - public: - LoggerImp(std::ostream* stream); - ~LoggerImp() override; - - Logger& operator<<(const Level &level) override; - Logger& operator<<(const std::string &message) override; - Logger& operator<<(const int &message) override; - Logger& operator<<(const unsigned int &message) override; - Logger& operator<<(const unsigned long& log) override; - Logger& operator<<(const float &message) override; - Logger& operator<<(const double &message) override; - - - private: - std::string getRankString(); - static bool shouldBeLogged(); - - static std::string getTimeStamp(); - void addDebugInformation(std::string& message); - logging::Logger& log(const std::string &message); - - private: - std::map<Logger::Level, std::string> levelString; - bool newLoggingLine = true; - }; - -} - +class BASICS_EXPORT LoggerImp : public Logger +{ +public: + LoggerImp(std::ostream *stream); + ~LoggerImp() override; + + Logger &operator<<(const Level &level) override; + Logger &operator<<(const std::string &message) override; + Logger &operator<<(const int &message) override; + Logger &operator<<(const unsigned int &message) override; + Logger &operator<<(const unsigned long &log) override; + Logger &operator<<(const float &message) override; + Logger &operator<<(const double &message) override; + +private: + std::string getRankString(); + static bool shouldBeLogged(); + + static std::string getTimeStamp(); + void addDebugInformation(std::string &message); + logging::Logger &log(const std::string &message); + +private: + std::map<Logger::Level, std::string> levelString; + bool newLoggingLine = true; +}; + +} // namespace logging #endif diff --git a/src/basics/Core/Logger/implementations/LoggerTest.cpp b/src/basics/Core/Logger/implementations/LoggerTest.cpp index a3b97d697..2c4e4e681 100644 --- a/src/basics/Core/Logger/implementations/LoggerTest.cpp +++ b/src/basics/Core/Logger/implementations/LoggerTest.cpp @@ -4,7 +4,6 @@ #include "../Logger.h" - TEST(DISABLED_LoggerTest, logStringWithoutSettingLevels_WillPutTheLogMesssageIntoTheStream) { std::ostringstream stream; @@ -21,7 +20,8 @@ TEST(DISABLED_LoggerTest, logStringWithHighDebugLevel_logOnlyHighLevelMessages) logging::Logger::setStream(&stream); logging::Logger::setDebugLevel(logging::Logger::INFO_HIGH); - *logging::out << logging::Logger::INFO_LOW << "Low Debug Message\n" << logging::Logger::INFO_HIGH << "HIGH Debug Message\n"; + *logging::out << logging::Logger::INFO_LOW << "Low Debug Message\n" + << logging::Logger::INFO_HIGH << "HIGH Debug Message\n"; EXPECT_THAT(stream.str(), "[HIGH] HIGH Debug Message\n"); } @@ -35,7 +35,7 @@ TEST(DISABLED_LoggerTest, addTwoStreams_shouldWriteToBoth) logging::out->addStream(&stream2); logging::Logger::setDebugLevel(logging::Logger::INFO_LOW); - *logging::out << logging::Logger::INFO_LOW <<"Hello World\n"; + *logging::out << logging::Logger::INFO_LOW << "Hello World\n"; EXPECT_THAT(stream1.str(), "[LOW] Hello World\n"); EXPECT_THAT(stream2.str(), "[LOW] Hello World\n"); @@ -46,7 +46,8 @@ TEST(DISABLED_LoggerTest, splittetOutputShouldHaveDebugInformationOnce) std::ostringstream stream; logging::Logger::setStream(&stream); - *logging::out << logging::Logger::INFO_LOW << "Hello" << " World\n"; + *logging::out << logging::Logger::INFO_LOW << "Hello" + << " World\n"; EXPECT_THAT(stream.str(), "[LOW] Hello World\n"); } @@ -57,8 +58,8 @@ TEST(DISABLED_LoggerTest, enableTimeStampInOutput) logging::Logger::setStream(&stream); logging::Logger::timeStamp(logging::Logger::TimeStamp::ENABLE); - *logging::out << logging::Logger::INFO_LOW << "Hello" << " World\n"; - + *logging::out << logging::Logger::INFO_LOW << "Hello" + << " World\n"; + EXPECT_THAT(stream.str(), testing::StrNe("[LOW] Hello World\n")); } - diff --git a/src/basics/Core/NonCreatable.h b/src/basics/Core/NonCreatable.h index a93e4db68..b25fc808b 100644 --- a/src/basics/Core/NonCreatable.h +++ b/src/basics/Core/NonCreatable.h @@ -1,18 +1,16 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef NON_CREATABLE_H #define NON_CREATABLE_H - class NonCreatable { private: - NonCreatable() = delete; - NonCreatable( const NonCreatable& ) = delete; - NonCreatable& operator=( const NonCreatable& ) = delete; + NonCreatable() = delete; + NonCreatable(const NonCreatable &) = delete; + NonCreatable &operator=(const NonCreatable &) = delete; }; - #endif diff --git a/src/basics/Core/RealConstants.h b/src/basics/Core/RealConstants.h index b63ff444f..d353a341c 100644 --- a/src/basics/Core/RealConstants.h +++ b/src/basics/Core/RealConstants.h @@ -1,227 +1,223 @@ #ifndef REAL_CONSTANT_H #define REAL_CONSTANT_H - - #ifdef VF_DOUBLE_ACCURACY -#define c1o2 0.5 -#define c3o2 1.5 -#define c1o3 0.333333333333333 -#define c2o3 0.666666666666667 -#define c1o4 0.25 -#define c3o4 0.75 -#define c1o6 0.166666666666667 -#define c1o7 0.142857142857143 -#define c1o8 0.125 -#define c1o9 0.111111111111111 -#define c2o9 0.222222222222222 -#define c4o9 0.444444444444444 -#define c1o10 0.1 -#define c1o12 0.083333333333333 -#define c1o16 0.0625 -#define c3o16 0.1875 -#define c9o16 0.5625 -#define c1o18 0.055555555555556 -#define c1o20 0.05 -#define c19o20 0.95 -#define c21o20 1.05 -#define c1o24 0.041666666666667 -#define c1o27 0.037037037037037 -#define c3o32 0.09375 -#define c4o32 0.125 -#define c1o36 0.027777777777778 -#define c1o48 0.020833333333333 -#define c1o64 0.015625 -#define c3o64 0.046875 -#define c9o64 0.140625 -#define c27o64 0.421875 -#define c1o66 0.015151515151515 -#define c1o72 0.013888888888889 -#define c1o264 0.003787878787879 -#define c8o27 0.296296296296296 -#define c2o27 0.074074074074074 -#define c1o54 0.018518518518519 -#define c1o100 0.01 -#define c99o100 0.99 -#define c1o126 0.007936507936508 -#define c1o216 0.004629629629630 -#define c5o4 1.25 -#define c9o4 2.25 -#define c5o2 2.5 -#define c9o2 4.5 +#define c1o2 0.5 +#define c3o2 1.5 +#define c1o3 0.333333333333333 +#define c2o3 0.666666666666667 +#define c1o4 0.25 +#define c3o4 0.75 +#define c1o6 0.166666666666667 +#define c1o7 0.142857142857143 +#define c1o8 0.125 +#define c1o9 0.111111111111111 +#define c2o9 0.222222222222222 +#define c4o9 0.444444444444444 +#define c1o10 0.1 +#define c1o12 0.083333333333333 +#define c1o16 0.0625 +#define c3o16 0.1875 +#define c9o16 0.5625 +#define c1o18 0.055555555555556 +#define c1o20 0.05 +#define c19o20 0.95 +#define c21o20 1.05 +#define c1o24 0.041666666666667 +#define c1o27 0.037037037037037 +#define c3o32 0.09375 +#define c4o32 0.125 +#define c1o36 0.027777777777778 +#define c1o48 0.020833333333333 +#define c1o64 0.015625 +#define c3o64 0.046875 +#define c9o64 0.140625 +#define c27o64 0.421875 +#define c1o66 0.015151515151515 +#define c1o72 0.013888888888889 +#define c1o264 0.003787878787879 +#define c8o27 0.296296296296296 +#define c2o27 0.074074074074074 +#define c1o54 0.018518518518519 +#define c1o100 0.01 +#define c99o100 0.99 +#define c1o126 0.007936507936508 +#define c1o216 0.004629629629630 +#define c5o4 1.25 +#define c9o4 2.25 +#define c5o2 2.5 +#define c9o2 4.5 -#define c0o1 0. -#define c1o1 1. -#define c2o1 2. -#define c3o1 3. -#define c4o1 4. -#define c5o1 5. -#define c6o1 6. -#define c7o1 7. -#define c8o1 8. -#define c9o1 9. -#define c10o1 10. -#define c11o1 11. -#define c12o1 12. -#define c13o1 13. -#define c14o1 14. -#define c15o1 15. -#define c16o1 16. -#define c17o1 17. -#define c18o1 18. -#define c21o1 21. -#define c24o1 24. -#define c25o1 25. -#define c26o1 26. -#define c27o1 27. -#define c28o1 28. -#define c29o1 29. -#define c30o1 30. -#define c32o1 32. -#define c33o1 33. -#define c34o1 34. -#define c36o1 36. -#define c40o1 40. -#define c42o1 42. -#define c46o1 46. -#define c48o1 48. -#define c50o1 50. -#define c52o1 52. -#define c54o1 54. -#define c56o1 56. -#define c64o1 64. -#define c66o1 66. -#define c68o1 68. -#define c69o1 69. -#define c72o1 72. -#define c84o1 84. -#define c88o1 88. -#define c96o1 96. -#define c100o1 100.0 -#define c130o1 130.0 -#define c152o1 152.0 -#define c166o1 166.0 -#define c195o1 195.0 -#define c216o1 216.0 -#define c264o1 264.0 -#define c290o1 290.0 -#define c367o1 367.0 +#define c0o1 0. +#define c1o1 1. +#define c2o1 2. +#define c3o1 3. +#define c4o1 4. +#define c5o1 5. +#define c6o1 6. +#define c7o1 7. +#define c8o1 8. +#define c9o1 9. +#define c10o1 10. +#define c11o1 11. +#define c12o1 12. +#define c13o1 13. +#define c14o1 14. +#define c15o1 15. +#define c16o1 16. +#define c17o1 17. +#define c18o1 18. +#define c21o1 21. +#define c24o1 24. +#define c25o1 25. +#define c26o1 26. +#define c27o1 27. +#define c28o1 28. +#define c29o1 29. +#define c30o1 30. +#define c32o1 32. +#define c33o1 33. +#define c34o1 34. +#define c36o1 36. +#define c40o1 40. +#define c42o1 42. +#define c46o1 46. +#define c48o1 48. +#define c50o1 50. +#define c52o1 52. +#define c54o1 54. +#define c56o1 56. +#define c64o1 64. +#define c66o1 66. +#define c68o1 68. +#define c69o1 69. +#define c72o1 72. +#define c84o1 84. +#define c88o1 88. +#define c96o1 96. +#define c100o1 100.0 +#define c130o1 130.0 +#define c152o1 152.0 +#define c166o1 166.0 +#define c195o1 195.0 +#define c216o1 216.0 +#define c264o1 264.0 +#define c290o1 290.0 +#define c367o1 367.0 -#define Op0000002 0.0000002 -#define c10eM30 1e-30 -#define c10eM10 1e-10 +#define Op0000002 0.0000002 +#define c10eM30 1e-30 +#define c10eM10 1e-10 #define smallSingle 0.0000000002 - #else -#define c1o2 0.5f -#define c3o2 1.5f -#define c1o3 (1.0f/3.0f) -#define c2o3 (2.0f/3.0f) -#define c1o4 0.25f -#define c3o4 0.75f -#define c1o6 (1.0f/6.0f) -#define c1o7 (1.0f/7.0f) -#define c1o8 0.125f -#define c1o9 (1.0f/9.0f) -#define c2o9 (2.0f/9.0f) -#define c4o9 (4.0f/9.0f) -#define c1o10 0.1f -#define c1o12 (1.0f/12.0f) -#define c1o16 0.0625f -#define c3o16 0.1875f -#define c9o16 0.5625f -#define c1o18 (1.0f/18.0f) -#define c1o20 0.05f -#define c19o20 0.95f -#define c21o20 1.05f -#define c1o24 (1.0f/24.0f) -#define c1o27 (1.0f/27.0f) -#define c3o32 0.09375f -#define c4o32 0.125f -#define c1o36 (1.0f/36.0f) -#define c1o48 (1.0f/48.0f) -#define c1o64 0.015625f -#define c3o64 0.046875f -#define c9o64 0.140625f -#define c27o64 0.421875f -#define c1o66 (1.0f/66.0f) -#define c1o72 (1.0f/72.0f) -#define c1o264 (1.0f/264.0f) -#define c8o27 (8.0f/27.0f) -#define c2o27 (2.0f/27.0f) -#define c1o54 (1.0f/54.0f) -#define c1o100 0.01f -#define c99o100 0.99f -#define c1o126 (1.0f/126.0f) -#define c1o216 (1.0f/216.0f) -#define c5o4 1.25f -#define c9o4 2.25f -#define c5o2 2.5f -#define c9o2 4.5f +#define c1o2 0.5f +#define c3o2 1.5f +#define c1o3 (1.0f / 3.0f) +#define c2o3 (2.0f / 3.0f) +#define c1o4 0.25f +#define c3o4 0.75f +#define c1o6 (1.0f / 6.0f) +#define c1o7 (1.0f / 7.0f) +#define c1o8 0.125f +#define c1o9 (1.0f / 9.0f) +#define c2o9 (2.0f / 9.0f) +#define c4o9 (4.0f / 9.0f) +#define c1o10 0.1f +#define c1o12 (1.0f / 12.0f) +#define c1o16 0.0625f +#define c3o16 0.1875f +#define c9o16 0.5625f +#define c1o18 (1.0f / 18.0f) +#define c1o20 0.05f +#define c19o20 0.95f +#define c21o20 1.05f +#define c1o24 (1.0f / 24.0f) +#define c1o27 (1.0f / 27.0f) +#define c3o32 0.09375f +#define c4o32 0.125f +#define c1o36 (1.0f / 36.0f) +#define c1o48 (1.0f / 48.0f) +#define c1o64 0.015625f +#define c3o64 0.046875f +#define c9o64 0.140625f +#define c27o64 0.421875f +#define c1o66 (1.0f / 66.0f) +#define c1o72 (1.0f / 72.0f) +#define c1o264 (1.0f / 264.0f) +#define c8o27 (8.0f / 27.0f) +#define c2o27 (2.0f / 27.0f) +#define c1o54 (1.0f / 54.0f) +#define c1o100 0.01f +#define c99o100 0.99f +#define c1o126 (1.0f / 126.0f) +#define c1o216 (1.0f / 216.0f) +#define c5o4 1.25f +#define c9o4 2.25f +#define c5o2 2.5f +#define c9o2 4.5f -#define c0o1 0.f -#define c1o1 1.f -#define c2o1 2.f -#define c3o1 3.f -#define c4o1 4.f -#define c5o1 5.f -#define c6o1 6.f -#define c7o1 7.f -#define c8o1 8.f -#define c9o1 9.f -#define c10o1 10.f -#define c11o1 11.f -#define c12o1 12.f -#define c13o1 13.f -#define c14o1 14.f -#define c15o1 15.f -#define c16o1 16.f -#define c17o1 17.f -#define c18o1 18.f -#define c21o1 21.f -#define c24o1 24.f -#define c25o1 25.f -#define c26o1 26.f -#define c27o1 27.f -#define c28o1 28.f -#define c29o1 29.f -#define c30o1 30.f -#define c32o1 32.f -#define c33o1 33.f -#define c34o1 34.f -#define c36o1 36.f -#define c40o1 40.f -#define c42o1 42.f -#define c46o1 46.f -#define c48o1 48.f -#define c50o1 50.f -#define c52o1 52.f -#define c54o1 54.f -#define c56o1 56.f -#define c64o1 64.f -#define c66o1 66.f -#define c68o1 68.f -#define c69o1 69.f -#define c72o1 72.f -#define c84o1 84.f -#define c88o1 88.f -#define c96o1 96.f -#define c100o1 100.0f -#define c130o1 130.0f -#define c152o1 152.0f -#define c166o1 166.0f -#define c195o1 195.0f -#define c216o1 216.0f -#define c264o1 264.0f -#define c290o1 290.0f -#define c367o1 367.0f +#define c0o1 0.f +#define c1o1 1.f +#define c2o1 2.f +#define c3o1 3.f +#define c4o1 4.f +#define c5o1 5.f +#define c6o1 6.f +#define c7o1 7.f +#define c8o1 8.f +#define c9o1 9.f +#define c10o1 10.f +#define c11o1 11.f +#define c12o1 12.f +#define c13o1 13.f +#define c14o1 14.f +#define c15o1 15.f +#define c16o1 16.f +#define c17o1 17.f +#define c18o1 18.f +#define c21o1 21.f +#define c24o1 24.f +#define c25o1 25.f +#define c26o1 26.f +#define c27o1 27.f +#define c28o1 28.f +#define c29o1 29.f +#define c30o1 30.f +#define c32o1 32.f +#define c33o1 33.f +#define c34o1 34.f +#define c36o1 36.f +#define c40o1 40.f +#define c42o1 42.f +#define c46o1 46.f +#define c48o1 48.f +#define c50o1 50.f +#define c52o1 52.f +#define c54o1 54.f +#define c56o1 56.f +#define c64o1 64.f +#define c66o1 66.f +#define c68o1 68.f +#define c69o1 69.f +#define c72o1 72.f +#define c84o1 84.f +#define c88o1 88.f +#define c96o1 96.f +#define c100o1 100.0f +#define c130o1 130.0f +#define c152o1 152.0f +#define c166o1 166.0f +#define c195o1 195.0f +#define c216o1 216.0f +#define c264o1 264.0f +#define c290o1 290.0f +#define c367o1 367.0f -#define Op0000002 0.0000002f -#define c10eM30 1e-30 -#define c10eM10 1e-10 +#define Op0000002 0.0000002f +#define c10eM30 1e-30 +#define c10eM10 1e-10 #define smallSingle 0.0000000002f #endif - #endif \ No newline at end of file diff --git a/src/basics/Core/StringUtilities/StringUtil.cpp b/src/basics/Core/StringUtilities/StringUtil.cpp index 8fd31c718..31496beae 100644 --- a/src/basics/Core/StringUtilities/StringUtil.cpp +++ b/src/basics/Core/StringUtilities/StringUtil.cpp @@ -3,7 +3,7 @@ #include <regex> #include <sstream> -std::string StringUtil::findAndReplace(const std::string &source, const std::string& find, const std::string& replace) +std::string StringUtil::findAndReplace(const std::string &source, const std::string &find, const std::string &replace) { std::string output = source; size_t j; @@ -12,26 +12,23 @@ std::string StringUtil::findAndReplace(const std::string &source, const std::str return output; } -std::string StringUtil::makeUpper(const std::string& instring) +std::string StringUtil::makeUpper(const std::string &instring) { std::string output = instring; transform(output.begin(), output.end(), output.begin(), ::toupper); return output; } -std::string StringUtil::makeLower(const std::string& instring) +std::string StringUtil::makeLower(const std::string &instring) { std::string output = instring; transform(output.begin(), output.end(), output.begin(), ::tolower); return output; } -bool StringUtil::contains(const std::string& source, const char *find) -{ - return (0 != strstr(source.c_str(), find)); -} +bool StringUtil::contains(const std::string &source, const char *find) { return (0 != strstr(source.c_str(), find)); } -std::string StringUtil::pad(const std::string& input, char pad, int length) +std::string StringUtil::pad(const std::string &input, char pad, int length) { std::string outstring = input; for (int i = (int)outstring.length(); i < length; ++i) @@ -43,51 +40,39 @@ std::string StringUtil::trim(const std::string &input, const std::string &trim / { if (input.size() == 0) return input; - std::string temp = ""; + std::string temp = ""; std::string::size_type begpos = input.find_first_not_of(trim); - if (begpos == std::string::npos) - { + if (begpos == std::string::npos) { return temp; - } - else - { + } else { std::string::size_type endpos = input.find_last_not_of(trim); - temp = input.substr(begpos, endpos - begpos + 1); + temp = input.substr(begpos, endpos - begpos + 1); } return temp; } -int StringUtil::toInt(const std::string &input) -{ - return std::stoi(input); -} +int StringUtil::toInt(const std::string &input) { return std::stoi(input); } -float StringUtil::toFloat(const std::string &input) -{ - return std::stof(input); -} +float StringUtil::toFloat(const std::string &input) { return std::stof(input); } -double StringUtil::toDouble(const std::string &input) -{ - return std::stod(input); -} +double StringUtil::toDouble(const std::string &input) { return std::stod(input); } bool StringUtil::toBool(const std::string &input) { - bool b {false}; + bool b{ false }; std::string trimmedInput = trim(input); if (!toBool(b, trimmedInput, std::boolalpha)) throw "StringUtils::toBool() - Not a bool: " + trimmedInput; return b; } -bool StringUtil::toBool(bool &t, const std::string &input, std::ios_base &(*f)(std::ios_base&)) +bool StringUtil::toBool(bool &t, const std::string &input, std::ios_base &(*f)(std::ios_base &)) { std::istringstream iss(input); return !(iss >> f >> t).fail(); } -std::vector<std::string> split(const std::string& str, char delim = ' ') +std::vector<std::string> split(const std::string &str, char delim = ' ') { std::stringstream ss(str); std::string token; @@ -98,91 +83,84 @@ std::vector<std::string> split(const std::string& str, char delim = ' ') return list; } -std::vector<std::string> StringUtil::split(const std::string& input, const std::string& delim/*= " "*/) +std::vector<std::string> StringUtil::split(const std::string &input, const std::string &delim /*= " "*/) { std::stringstream ss; ss << "[" << delim << "]"; std::regex re(ss.str()); - std::sregex_token_iterator first{input.begin(), input.end(), re, -1}, last; //the '-1' is what makes the regex split (-1 := what was not matched) - std::vector<std::string> tokens{first, last}; - tokens.erase(std::remove_if(tokens.begin(), tokens.end(), [](std::string& token) - { - return token.empty(); - }), tokens.end()); + std::sregex_token_iterator first{ input.begin(), input.end(), re, -1 }, + last; // the '-1' is what makes the regex split (-1 := what was not matched) + std::vector<std::string> tokens{ first, last }; + tokens.erase(std::remove_if(tokens.begin(), tokens.end(), [](std::string &token) { return token.empty(); }), + tokens.end()); return tokens; } -std::vector<int> StringUtil::toIntVector(const std::string& input) +std::vector<int> StringUtil::toIntVector(const std::string &input) { std::vector<int> v; std::vector<std::string> inputEntries; inputEntries = split(input, " \n\t"); - for(std::string entry : inputEntries) + for (std::string entry : inputEntries) if (entry != "") v.push_back(toInt(entry)); return v; } -std::vector<unsigned int> StringUtil::toUintVector(const std::string & input) +std::vector<unsigned int> StringUtil::toUintVector(const std::string &input) { - std::vector<unsigned int> v; - std::vector<std::string> inputEntries; + std::vector<unsigned int> v; + std::vector<std::string> inputEntries; inputEntries = split(input, " \n\t"); - for(std::string entry : inputEntries) - if (entry != "") - v.push_back(toInt(entry)); - return v; + for (std::string entry : inputEntries) + if (entry != "") + v.push_back(toInt(entry)); + return v; } -std::vector<bool> StringUtil::toBoolVector(const std::string & input) +std::vector<bool> StringUtil::toBoolVector(const std::string &input) { - std::vector<bool> v; - std::vector<std::string> inputEntries; + std::vector<bool> v; + std::vector<std::string> inputEntries; inputEntries = split(input, " \n\t"); - for(std::string entry : inputEntries) - { - bool b {false}; - std::string trimmedInput = trim(input); - if (toBool(b, trimmedInput, std::noboolalpha)) - v.push_back(b); - } - return v; + for (std::string entry : inputEntries) { + bool b{ false }; + std::string trimmedInput = trim(input); + if (toBool(b, trimmedInput, std::noboolalpha)) + v.push_back(b); + } + return v; } -std::vector<std::string> StringUtil::toStringVector(const std::string & input) -{ - return split(input, " \n\t"); -} +std::vector<std::string> StringUtil::toStringVector(const std::string &input) { return split(input, " \n\t"); } -BASICS_EXPORT std::vector<double> StringUtil::toDoubleVector(const std::string & input) +BASICS_EXPORT std::vector<double> StringUtil::toDoubleVector(const std::string &input) { - std::vector<double> v; - std::vector<std::string> inputEntries; + std::vector<double> v; + std::vector<std::string> inputEntries; inputEntries = split(input, " \n\t"); - for(std::string entry : inputEntries) - if (entry != "") - v.push_back(toDouble(entry)); - return v; + for (std::string entry : inputEntries) + if (entry != "") + v.push_back(toDouble(entry)); + return v; } -template<typename T> -std::string StringUtil::toString(const T& t) +template <typename T> +std::string StringUtil::toString(const T &t) { std::ostringstream stream; stream << t; return stream.str(); } -template BASICS_EXPORT std::string StringUtil::toString<int>(const int& t); - - +template BASICS_EXPORT std::string StringUtil::toString<int>(const int &t); bool StringUtil::endsWith(const std::string &input, const std::string &end) { if (input.length() >= end.length()) { - return (0 == input.compare (input.length() - end.length(), end.length(), end)); + return (0 == input.compare(input.length() - end.length(), end.length(), end)); } else { return false; } diff --git a/src/basics/Core/StringUtilities/StringUtil.h b/src/basics/Core/StringUtilities/StringUtil.h index 63ee9e965..cdf8dce29 100644 --- a/src/basics/Core/StringUtilities/StringUtil.h +++ b/src/basics/Core/StringUtilities/StringUtil.h @@ -2,47 +2,49 @@ #define STRINGUTIL_H #include <algorithm> -#include <sstream> #include <iostream> +#include <sstream> #include <string> #include <vector> #include "basics_export.h" -#define SSTR( x ) static_cast< std::ostringstream & >( \ - ( std::ostringstream() << std::dec << x ) ).str() +#define SSTR(x) static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x)).str() class StringUtil { public: - static BASICS_EXPORT std::string findAndReplace(const std::string &source, const std::string& find, const std::string& replace); - static BASICS_EXPORT std::string makeUpper(const std::string& instring); - static BASICS_EXPORT std::string makeLower(const std::string& instring); - static BASICS_EXPORT std::vector<std::string> split(const std::string& input, const std::string& delim = " "); - static BASICS_EXPORT bool contains(const std::string& source, const char *find); - static BASICS_EXPORT std::string pad(const std::string& input, char pad, int length); + static BASICS_EXPORT std::string findAndReplace(const std::string &source, const std::string &find, + const std::string &replace); + static BASICS_EXPORT std::string makeUpper(const std::string &instring); + static BASICS_EXPORT std::string makeLower(const std::string &instring); + static BASICS_EXPORT std::vector<std::string> split(const std::string &input, const std::string &delim = " "); + static BASICS_EXPORT bool contains(const std::string &source, const char *find); + static BASICS_EXPORT std::string pad(const std::string &input, char pad, int length); static BASICS_EXPORT std::string trim(const std::string &input, const std::string &trim = std::string(" \t\n")); static BASICS_EXPORT int toInt(const std::string &input); static BASICS_EXPORT float toFloat(const std::string &input); static BASICS_EXPORT double toDouble(const std::string &input); static BASICS_EXPORT bool toBool(const std::string &input); - static BASICS_EXPORT std::vector<int> toIntVector(const std::string& s); - static BASICS_EXPORT std::vector<unsigned int> toUintVector(const std::string& s); - static BASICS_EXPORT std::vector<bool> toBoolVector(const std::string& s); - static BASICS_EXPORT std::vector<std::string> toStringVector(const std::string& s); - static BASICS_EXPORT std::vector<double> toDoubleVector(const std::string& s); - template<typename T> - static BASICS_EXPORT std::string toString(const T& t); + static BASICS_EXPORT std::vector<int> toIntVector(const std::string &s); + static BASICS_EXPORT std::vector<unsigned int> toUintVector(const std::string &s); + static BASICS_EXPORT std::vector<bool> toBoolVector(const std::string &s); + static BASICS_EXPORT std::vector<std::string> toStringVector(const std::string &s); + static BASICS_EXPORT std::vector<double> toDoubleVector(const std::string &s); + template <typename T> + static BASICS_EXPORT std::string toString(const T &t); static BASICS_EXPORT bool endsWith(const std::string &input, const std::string &end); private: - StringUtil() = default;; - StringUtil(const StringUtil&) = default;; - virtual ~StringUtil() = default;; - - static bool toBool(bool &t, const std::string &input, std::ios_base &(*f)(std::ios_base&)); + StringUtil() = default; + ; + StringUtil(const StringUtil &) = default; + ; + virtual ~StringUtil() = default; + ; + + static bool toBool(bool &t, const std::string &input, std::ios_base &(*f)(std::ios_base &)); }; #endif - diff --git a/src/basics/Core/StringUtilities/StringUtilTest.cpp b/src/basics/Core/StringUtilities/StringUtilTest.cpp index e87e15423..52f9511b3 100644 --- a/src/basics/Core/StringUtilities/StringUtilTest.cpp +++ b/src/basics/Core/StringUtilities/StringUtilTest.cpp @@ -15,47 +15,47 @@ int main(int argc, char *argv[]) TEST(StringUtilTest, endsWith_shouldReturnTrue) { - const std::string input {"input_string"}; - const std::string ends_with {"string"}; + const std::string input{ "input_string" }; + const std::string ends_with{ "string" }; ASSERT_TRUE(StringUtil::endsWith(input, ends_with)); } TEST(StringUtilTest, endsWith_shouldReturnFalse) { - const std::string input {"input_string"}; - const std::string ends_with {"string_"}; + const std::string input{ "input_string" }; + const std::string ends_with{ "string_" }; ASSERT_FALSE(StringUtil::endsWith(input, ends_with)); } TEST(StringUtilTest, toIntVector) { - const std::string input {"1 2\n3 4"}; - std::vector<int> expected_result {1, 2, 3, 4}; + const std::string input{ "1 2\n3 4" }; + std::vector<int> expected_result{ 1, 2, 3, 4 }; auto result = StringUtil::toIntVector(input); - ASSERT_THAT(result,testing::Eq(expected_result)); + ASSERT_THAT(result, testing::Eq(expected_result)); } TEST(StringUtilTest, splitIntoStringsWithDelimeter) { - const std::string input {"1 2\n3 4\t5"}; - const std::string delimeter {" \n\t"}; - std::vector<std::string> expected_result {"1", "2", "3", "4", "5"}; + const std::string input{ "1 2\n3 4\t5" }; + const std::string delimeter{ " \n\t" }; + std::vector<std::string> expected_result{ "1", "2", "3", "4", "5" }; auto result = StringUtil::split(input, delimeter); - ASSERT_THAT(result,testing::Eq(expected_result)); + ASSERT_THAT(result, testing::Eq(expected_result)); } TEST(StringUtilTest, toStringVector) { - const std::string input {"1 2\n3 4\t5"}; - std::vector<std::string> expected_result {"1", "2", "3", "4", "5"}; + const std::string input{ "1 2\n3 4\t5" }; + std::vector<std::string> expected_result{ "1", "2", "3", "4", "5" }; auto result = StringUtil::toStringVector(input); - ASSERT_THAT(result,testing::Eq(expected_result)); + ASSERT_THAT(result, testing::Eq(expected_result)); } \ No newline at end of file diff --git a/src/basics/Core/Timer/Timer.h b/src/basics/Core/Timer/Timer.h index 702cfafb4..e8a97000f 100644 --- a/src/basics/Core/Timer/Timer.h +++ b/src/basics/Core/Timer/Timer.h @@ -13,11 +13,10 @@ public: static SPtr<Timer> makeStart(); virtual void start() = 0; - virtual void end() = 0; + virtual void end() = 0; - virtual real getTimeInSeconds() const = 0; + virtual real getTimeInSeconds() const = 0; virtual real getCurrentRuntimeInSeconds() const = 0; }; #endif - diff --git a/src/basics/Core/Timer/TimerImp.cpp b/src/basics/Core/Timer/TimerImp.cpp index 7942f970a..7aef3e999 100644 --- a/src/basics/Core/Timer/TimerImp.cpp +++ b/src/basics/Core/Timer/TimerImp.cpp @@ -1,22 +1,18 @@ #include "TimerImp.h" +void TimerImp::start() { this->startTime = std::chrono::high_resolution_clock::now(); } -void TimerImp::start() -{ - this->startTime = std::chrono::high_resolution_clock::now(); -} - -void TimerImp::end() -{ - this->endTime = std::chrono::high_resolution_clock::now(); -} +void TimerImp::end() { this->endTime = std::chrono::high_resolution_clock::now(); } real TimerImp::getTimeInSeconds() const { - return real(std::chrono::duration_cast<std::chrono::microseconds>( endTime - startTime ).count() / 1000000.0); + return real(std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime).count() / 1000000.0); } real TimerImp::getCurrentRuntimeInSeconds() const { - return real(std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now() - startTime ).count() / 1000000.0); + return real( + std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - startTime) + .count() / + 1000000.0); } diff --git a/src/basics/Core/Timer/TimerImp.h b/src/basics/Core/Timer/TimerImp.h index 9759b9daa..bcc078db9 100644 --- a/src/basics/Core/Timer/TimerImp.h +++ b/src/basics/Core/Timer/TimerImp.h @@ -5,10 +5,8 @@ #include <chrono> - #include "DataTypes.h" - class BASICS_EXPORT TimerImp : public Timer { public: @@ -26,4 +24,3 @@ private: }; #endif - diff --git a/src/basics/Core/VectorTypes.cpp b/src/basics/Core/VectorTypes.cpp index 59c3d80c8..dab267509 100644 --- a/src/basics/Core/VectorTypes.cpp +++ b/src/basics/Core/VectorTypes.cpp @@ -1,20 +1,8 @@ #include "VectorTypes.h" -//Vec3 Vec3::operator+( Vec3& left, Vec3& right ){ -Vec3 Vec3::operator+( Vec3& right ){ - return { this->x + right.x, - this->y + right.y, - this->z + right.z }; -} +// Vec3 Vec3::operator+( Vec3& left, Vec3& right ){ +Vec3 Vec3::operator+(Vec3 &right) { return { this->x + right.x, this->y + right.y, this->z + right.z }; } -Vec3 Vec3::operator-( Vec3& right ){ - return { this->x - right.x, - this->y - right.y, - this->z - right.z }; -} +Vec3 Vec3::operator-(Vec3 &right) { return { this->x - right.x, this->y - right.y, this->z - right.z }; } -Vec3 operator*( real scalar, Vec3& vec ){ - return { scalar * vec.x, - scalar * vec.y, - scalar * vec.z }; -} +Vec3 operator*(real scalar, Vec3 &vec) { return { scalar * vec.x, scalar * vec.y, scalar * vec.z }; } diff --git a/src/basics/Core/VectorTypes.h b/src/basics/Core/VectorTypes.h index d59771bf9..0256a960d 100644 --- a/src/basics/Core/VectorTypes.h +++ b/src/basics/Core/VectorTypes.h @@ -16,21 +16,19 @@ #include "RealConstants.h" struct BASICS_EXPORT Vec3 { - real x{c0o1}, y{c0o1}, z{c0o1}; + real x{ c0o1 }, y{ c0o1 }, z{ c0o1 }; __host__ __device__ Vec3(real x, real y, real z) : x(x), y(y), z(z) {} - __host__ __device__ Vec3() = default; + __host__ __device__ Vec3() = default; - __host__ __device__ real length() { - return std::sqrt( x*x + y*y + z*z ); - } + __host__ __device__ real length() { return std::sqrt(x * x + y * y + z * z); } - Vec3 operator+( Vec3& right ); - Vec3 operator-( Vec3& right ); + Vec3 operator+(Vec3 &right); + Vec3 operator-(Vec3 &right); }; -//BASICS_EXPORT Vec3 operator+( Vec3& left, Vec3& right ); -//BASICS_EXPORT Vec3 operator-( Vec3& left, Vec3& right ); -BASICS_EXPORT Vec3 operator*( real scalar, Vec3& vec ); +// BASICS_EXPORT Vec3 operator+( Vec3& left, Vec3& right ); +// BASICS_EXPORT Vec3 operator-( Vec3& left, Vec3& right ); +BASICS_EXPORT Vec3 operator*(real scalar, Vec3 &vec); #endif diff --git a/src/basics/Core/buildInfo.h b/src/basics/Core/buildInfo.h index b9ba18ec0..a5499518c 100644 --- a/src/basics/Core/buildInfo.h +++ b/src/basics/Core/buildInfo.h @@ -1,26 +1,23 @@ #ifndef buildInfo_H #define buildInfo_H - namespace buildInfo { - const char * gitCommitHash(); - const char * gitBranch(); - const char * buildType(); - const char * compilerFlags(); - const char * buildMachine(); - const char * projectDir(); - const char * binaryDir(); -} - -#define GIT_COMMIT_HASH buildinfo::gitCommitHash() -#define GIT_BRANCH buildinfo::gitBranch() -#define BUILD_MACHINE buildinfo::buildMachine() -#define PROJECT_DIR buildinfo::projectDir() -#define BINARY_DIR buildinfo::binaryDir() -#define COMPILER_FLAGS buildinfo::compilerFlags() -#define BUILD_TYPE buildinfo::buildType() - +const char *gitCommitHash(); +const char *gitBranch(); +const char *buildType(); +const char *compilerFlags(); +const char *buildMachine(); +const char *projectDir(); +const char *binaryDir(); +} // namespace buildInfo +#define GIT_COMMIT_HASH buildinfo::gitCommitHash() +#define GIT_BRANCH buildinfo::gitBranch() +#define BUILD_MACHINE buildinfo::buildMachine() +#define PROJECT_DIR buildinfo::projectDir() +#define BINARY_DIR buildinfo::binaryDir() +#define COMPILER_FLAGS buildinfo::compilerFlags() +#define BUILD_TYPE buildinfo::buildType() #endif diff --git a/src/basics/Core/buildInfo.in.cpp b/src/basics/Core/buildInfo.in.cpp index 2cd55e865..56f302208 100644 --- a/src/basics/Core/buildInfo.in.cpp +++ b/src/basics/Core/buildInfo.in.cpp @@ -2,14 +2,13 @@ #include "basics_export.h" - namespace buildInfo { - BASICS_EXPORT const char *gitCommitHash() { return "@git_commit_hash@"; } - BASICS_EXPORT const char *gitBranch() { return "@git_branch@"; } - BASICS_EXPORT const char *buildType() { return "@CMAKE_BUILD_TYPE@"; } - BASICS_EXPORT const char *compilerFlags() { return "@COMPILER_FLAGS@"; } - BASICS_EXPORT const char *buildMachine() { return "@BUILD_computerName@";} - BASICS_EXPORT const char *projectDir() { return "@CMAKE_SOURCE_DIR@"; } - BASICS_EXPORT const char *binaryDir() { return "@CMAKE_BINARY_DIR@"; } -} +BASICS_EXPORT const char *gitCommitHash() { return "@git_commit_hash@"; } +BASICS_EXPORT const char *gitBranch() { return "@git_branch@"; } +BASICS_EXPORT const char *buildType() { return "@CMAKE_BUILD_TYPE@"; } +BASICS_EXPORT const char *compilerFlags() { return "@COMPILER_FLAGS@"; } +BASICS_EXPORT const char *buildMachine() { return "@BUILD_computerName@"; } +BASICS_EXPORT const char *projectDir() { return "@CMAKE_SOURCE_DIR@"; } +BASICS_EXPORT const char *binaryDir() { return "@CMAKE_BINARY_DIR@"; } +} // namespace buildInfo diff --git a/src/basics/PointerDefinitions.h b/src/basics/PointerDefinitions.h index 07462b89e..4b8657025 100644 --- a/src/basics/PointerDefinitions.h +++ b/src/basics/PointerDefinitions.h @@ -1,13 +1,12 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef SHARED_POINTER_H #define SHARED_POINTER_H #include <memory> - template <class T> using SPtr = std::shared_ptr<T>; @@ -18,7 +17,7 @@ template <class T> using UPtr = std::unique_ptr<T>; template <class T> -using RPtr = T*; +using RPtr = T *; template <class T> using enableSharedFromThis = std::enable_shared_from_this<T>; diff --git a/src/basics/basics/container/CbArray2D.h b/src/basics/basics/container/CbArray2D.h index 107bc386f..79e8a9c3a 100644 --- a/src/basics/basics/container/CbArray2D.h +++ b/src/basics/basics/container/CbArray2D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,58 +35,63 @@ #include <iomanip> -#include <basics/utilities/UbException.h> -#include <basics/utilities/UbEqual.h> #include <algorithm> +#include <basics/utilities/UbEqual.h> +#include <basics/utilities/UbException.h> #include <typeinfo> ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // IndexClasses -//IndexerX2X1: +// IndexerX2X1: // 4 5 6 // Array 1 2 3 --> vector 1 2 3 4 5 6 -//optimaler schleifendurchlauf -//for(alle X2) +// optimaler schleifendurchlauf +// for(alle X2) // for(alle X1) class IndexerX2X1 { public: - using size_type = int; + using size_type = int; + public: - inline std::size_t getIndex(const size_type& x1, const size_type& x2, const size_type& nx1, const size_type& /*nx2*/) const - { - return nx1* x2 + x1; - } - inline std::size_t getStartIndexOfSortedArray(const size_type& /*x1*/, const size_type& x2, const size_type& nx1, const size_type& /*nx2*/) const - { - return nx1* x2; - } + inline std::size_t getIndex(const size_type &x1, const size_type &x2, const size_type &nx1, + const size_type & /*nx2*/) const + { + return nx1 * x2 + x1; + } + inline std::size_t getStartIndexOfSortedArray(const size_type & /*x1*/, const size_type &x2, const size_type &nx1, + const size_type & /*nx2*/) const + { + return nx1 * x2; + } }; -//IndexerX1X2: +// IndexerX1X2: // 4 5 6 // Array 1 2 3 --> vector 1 4 2 5 3 6 -//optimaler schleifendurchlauf -//for(alle X1) +// optimaler schleifendurchlauf +// for(alle X1) // for(alle X2) class IndexerX1X2 { public: - using size_type = int; + using size_type = int; + public: - inline std::size_t getIndex(const size_type& x1, const size_type& x2, const size_type& /*nx1*/,const size_type& nx2) const - { - return nx2* x1+ x2; - } - inline std::size_t getStartIndexOfSortedArray(const size_type& x1, const size_type& /*x2*/, const size_type& /*nx1*/, const size_type& nx2) const - { - return nx2* x1; - } + inline std::size_t getIndex(const size_type &x1, const size_type &x2, const size_type & /*nx1*/, + const size_type &nx2) const + { + return nx2 * x1 + x2; + } + inline std::size_t getStartIndexOfSortedArray(const size_type &x1, const size_type & /*x2*/, + const size_type & /*nx1*/, const size_type &nx2) const + { + return nx2 * x1; + } }; - ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // CbArray2D @@ -100,311 +105,284 @@ public: //! //! -release: not defined "NO_CB_RANGECHECK" && defined "CB_RANGECHECK" ////////////////////////////////////////////////////////////////////////// -template<typename T, typename IndexClass = IndexerX2X1> +template <typename T, typename IndexClass = IndexerX2X1> class CbArray2D { public: - using value_type = T; - using indexer_type = IndexClass; - using size_type = typename IndexClass::size_type; - using reference = typename std::vector<value_type>::reference; - using const_reference = typename std::vector<value_type>::const_reference; - using pointer = typename std::vector<value_type>::pointer; - using const_pointer = typename std::vector<value_type>::const_pointer; + using value_type = T; + using indexer_type = IndexClass; + using size_type = typename IndexClass::size_type; + using reference = typename std::vector<value_type>::reference; + using const_reference = typename std::vector<value_type>::const_reference; + using pointer = typename std::vector<value_type>::pointer; + using const_pointer = typename std::vector<value_type>::const_pointer; private: - template< typename value_type2, typename IndexClass2 > friend class CbArray2D; + template <typename value_type2, typename IndexClass2> + friend class CbArray2D; public: - /*=======================================================================*/ - CbArray2D() - { - this->resize(0,0); - } - /*=======================================================================*/ - CbArray2D(const size_type& nx2, const size_type& nx1) - { - this->resize(nx2,nx1); - } - /*=======================================================================*/ - CbArray2D(const size_type& nx2, const size_type& nx1, const value_type& val) - { - this->resize(nx2,nx1,val); - } - /*=======================================================================*/ - CbArray2D(const size_type& uniformDimensionSize /*nx1==nx2*/) - { - this->resize(uniformDimensionSize,uniformDimensionSize); - } - /*=======================================================================*/ - //ssbernimmt vector als daten vector! (erstellt KEINE kopie!!!, vec ist anschlieueend leer, da swap verwendet wird) - CbArray2D(std::vector<value_type>& vec, const size_type& nx1,const size_type& nx2) - { - assert( (nx1*nx2)==vec.size() ); - this->data.swap(vec); - this->resize(nx1,nx2); - } - /*=======================================================================*/ - CbArray2D(const CbArray2D& src) - : nx1(src.nx1) - , nx2(src.nx2) - , data(src.data) - { - } - /*=======================================================================*/ - template< typename value_type2 > - CbArray2D(const CbArray2D< value_type2 >& src) - : nx1(src.nx1) - , nx2(src.nx2) - { - //Sourcedaten kopieren - this->data.resize( src.data.size() ); - for(std::size_t i=0; i<data.size(); ++i) - this->data[i] = src.data[i]; - } - /*=======================================================================*/ - virtual ~CbArray2D() = default; - /*=======================================================================*/ - CbArray2D& operator= (const CbArray2D& rhs) - { - if(this == &rhs) return *this; + /*=======================================================================*/ + CbArray2D() { this->resize(0, 0); } + /*=======================================================================*/ + CbArray2D(const size_type &nx2, const size_type &nx1) { this->resize(nx2, nx1); } + /*=======================================================================*/ + CbArray2D(const size_type &nx2, const size_type &nx1, const value_type &val) { this->resize(nx2, nx1, val); } + /*=======================================================================*/ + CbArray2D(const size_type &uniformDimensionSize /*nx1==nx2*/) + { + this->resize(uniformDimensionSize, uniformDimensionSize); + } + /*=======================================================================*/ + // ssbernimmt vector als daten vector! (erstellt KEINE kopie!!!, vec ist anschlieueend leer, da swap verwendet wird) + CbArray2D(std::vector<value_type> &vec, const size_type &nx1, const size_type &nx2) + { + assert((nx1 * nx2) == vec.size()); + this->data.swap(vec); + this->resize(nx1, nx2); + } + /*=======================================================================*/ + CbArray2D(const CbArray2D &src) : nx1(src.nx1), nx2(src.nx2), data(src.data) {} + /*=======================================================================*/ + template <typename value_type2> + CbArray2D(const CbArray2D<value_type2> &src) : nx1(src.nx1), nx2(src.nx2) + { + // Sourcedaten kopieren + this->data.resize(src.data.size()); + for (std::size_t i = 0; i < data.size(); ++i) + this->data[i] = src.data[i]; + } + /*=======================================================================*/ + virtual ~CbArray2D() = default; + /*=======================================================================*/ + CbArray2D &operator=(const CbArray2D &rhs) + { + if (this == &rhs) + return *this; - this->nx1 = rhs.nx1; - this->nx2 = rhs.nx2; + this->nx1 = rhs.nx1; + this->nx2 = rhs.nx2; - //Laenge anpassen - this->data.resize(rhs.data.size()); - //gespeicherte Datenelemente loeschen - this->data.clear(); + // Laenge anpassen + this->data.resize(rhs.data.size()); + // gespeicherte Datenelemente loeschen + this->data.clear(); - //Sourcedaten kopieren - this->data = rhs.data; + // Sourcedaten kopieren + this->data = rhs.data; - return *this; - } - /*=======================================================================*/ - //durch value_type2 kann man z.B. ein float array einem double array zuweisen! - template< typename value_type2, typename IndexClass2 > - CbArray2D& operator= (const CbArray2D< value_type2, IndexClass2 >& rhs) - { - this->nx1 = rhs.nx1; - this->nx2 = rhs.nx2; + return *this; + } + /*=======================================================================*/ + // durch value_type2 kann man z.B. ein float array einem double array zuweisen! + template <typename value_type2, typename IndexClass2> + CbArray2D &operator=(const CbArray2D<value_type2, IndexClass2> &rhs) + { + this->nx1 = rhs.nx1; + this->nx2 = rhs.nx2; - //gespeicherte Datenelemente loeschen - this->data.clear(); - //Laenge anpassen - this->data.resize(rhs.data.size()); + // gespeicherte Datenelemente loeschen + this->data.clear(); + // Laenge anpassen + this->data.resize(rhs.data.size()); - //Sourcedaten kopieren (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) - //ACHTUNG: fuer diese Konvertierung muss bei Klassen der demenstrechende operator - // implementiert sein, e.g.: class value_type2 {public: inline operator value_type2() const { return value_type2(); } - for(int x1=0; x1<this->nx1; x1++) - for(int x2=0; x2<this->nx2; x2++) - this->operator()(x1,x2) = static_cast< value_type >( rhs.operator()(x1,x2) ); + // Sourcedaten kopieren (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) + // ACHTUNG: fuer diese Konvertierung muss bei Klassen der demenstrechende operator + // implementiert sein, e.g.: class value_type2 {public: inline operator value_type2() const { return + // value_type2(); } + for (int x1 = 0; x1 < this->nx1; x1++) + for (int x2 = 0; x2 < this->nx2; x2++) + this->operator()(x1, x2) = static_cast<value_type>(rhs.operator()(x1, x2)); - return *this; - } - /*=======================================================================*/ - bool operator== (const CbArray2D& rhs) const - { - if( this == &rhs ) return true; + return *this; + } + /*=======================================================================*/ + bool operator==(const CbArray2D &rhs) const + { + if (this == &rhs) + return true; - if( this->nx1!=rhs.nx1 - || this->nx2!=rhs.nx2 - || this->data.size() != rhs.data.size() ) - { - return false; - } + if (this->nx1 != rhs.nx1 || this->nx2 != rhs.nx2 || this->data.size() != rhs.data.size()) { + return false; + } - return std::equal( this->data.begin(), this->data.end(), rhs.data.begin(), UbEqual<value_type, value_type >() ); - } - /*=======================================================================*/ - template< typename value_type2, typename IndexClass2 > - bool operator== (const CbArray2D< value_type2, IndexClass2 >& rhs) const - { - if( this->data.size() != rhs.data.size() ) return false; + return std::equal(this->data.begin(), this->data.end(), rhs.data.begin(), UbEqual<value_type, value_type>()); + } + /*=======================================================================*/ + template <typename value_type2, typename IndexClass2> + bool operator==(const CbArray2D<value_type2, IndexClass2> &rhs) const + { + if (this->data.size() != rhs.data.size()) + return false; - //Sourcedaten einzeln checken (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) - for(int x1=0; x1<this->nx1; x1++) - for(int x2=0; x2<this->nx2; x2++) - if( !isUbEqual(this->operator()(x1,x2), rhs.operator()(x1,x2)) ) - return false; + // Sourcedaten einzeln checken (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) + for (int x1 = 0; x1 < this->nx1; x1++) + for (int x2 = 0; x2 < this->nx2; x2++) + if (!isUbEqual(this->operator()(x1, x2), rhs.operator()(x1, x2))) + return false; - return true; - } - /*=======================================================================*/ - bool operator!= (const CbArray2D& rhs) const - { - return !(*this==rhs); - } - /*=======================================================================*/ - template< typename value_type2, typename IndexClass2 > - bool operator!= (const CbArray2D< value_type2, IndexClass2 >& rhs) const - { - return !(*this==rhs); - } - /*=======================================================================*/ - reference operator() (const size_type& x1,const size_type& x2) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2)) ); - #endif + return true; + } + /*=======================================================================*/ + bool operator!=(const CbArray2D &rhs) const { return !(*this == rhs); } + /*=======================================================================*/ + template <typename value_type2, typename IndexClass2> + bool operator!=(const CbArray2D<value_type2, IndexClass2> &rhs) const + { + return !(*this == rhs); + } + /*=======================================================================*/ + reference operator()(const size_type &x1, const size_type &x2) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2))); +#endif - return this->data[indexer.getIndex(x1,x2,nx1,nx2)]; - } - /*=======================================================================*/ - const_reference operator() (const size_type& x1,const size_type& x2) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2)) ); - #endif + return this->data[indexer.getIndex(x1, x2, nx1, nx2)]; + } + /*=======================================================================*/ + const_reference operator()(const size_type &x1, const size_type &x2) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2))); +#endif - return this->data[indexer.getIndex(x1,x2,nx1,nx2)]; - } - /*=======================================================================*/ - pointer getStartAdressOfSortedArray(const size_type& x1, const size_type& x2) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2)) ); - #endif - return &this->data[indexer.getStartIndexOfSortedArray(x1,x2,nx1,nx2)]; - } - /*=======================================================================*/ - const_pointer getStartAdressOfSortedArray(const size_type& x1, const size_type& x2) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2)) ); - #endif - return &this->data[indexer.getStartIndexOfSortedArray(x1,x2,nx1,nx2)]; - } - /*=======================================================================*/ - void setObject(const size_type& x1,const size_type& x2,const value_type& value) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2)) ); - #endif - this->data[indexer.getIndex(x1,x2,nx1,nx2)] = value; - } - /*=======================================================================*/ - reference getObject(const size_type& x1, const size_type& x2) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2)) ); - #endif - return this->data[indexer.getIndex(x1,x2,nx1,nx2)] ; - } - /*=======================================================================*/ - typename std::vector<value_type>::const_reference getObject(const size_type& x1, const size_type& x2) const - { - return this->operator()(x1,x2); - } - /*=======================================================================*/ - bool isEmpty() const { return data.empty(); } - size_type getNX1() const { return this->nx1; } - size_type getNX2() const { return this->nx2; } - /*=======================================================================*/ - void reset(const T& val) - { - std::fill( this->data.begin(), this->data.end(), val ); - } - /*=======================================================================*/ - std::string toString() const - { - std::stringstream text; - for(size_type x2=0; x2<this->nx2; x2++) - { - for(size_type x1=0; x1<this->nx1; x1++) - { - //hier kommts zum Konflikt ab und an ... - text<<this->getObject(x1,x2)<<", "; - } - text<<"\n"; - } + return this->data[indexer.getIndex(x1, x2, nx1, nx2)]; + } + /*=======================================================================*/ + pointer getStartAdressOfSortedArray(const size_type &x1, const size_type &x2) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2))); +#endif + return &this->data[indexer.getStartIndexOfSortedArray(x1, x2, nx1, nx2)]; + } + /*=======================================================================*/ + const_pointer getStartAdressOfSortedArray(const size_type &x1, const size_type &x2) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2))); +#endif + return &this->data[indexer.getStartIndexOfSortedArray(x1, x2, nx1, nx2)]; + } + /*=======================================================================*/ + void setObject(const size_type &x1, const size_type &x2, const value_type &value) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2))); +#endif + this->data[indexer.getIndex(x1, x2, nx1, nx2)] = value; + } + /*=======================================================================*/ + reference getObject(const size_type &x1, const size_type &x2) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2))); +#endif + return this->data[indexer.getIndex(x1, x2, nx1, nx2)]; + } + /*=======================================================================*/ + typename std::vector<value_type>::const_reference getObject(const size_type &x1, const size_type &x2) const + { + return this->operator()(x1, x2); + } + /*=======================================================================*/ + bool isEmpty() const { return data.empty(); } + size_type getNX1() const { return this->nx1; } + size_type getNX2() const { return this->nx2; } + /*=======================================================================*/ + void reset(const T &val) { std::fill(this->data.begin(), this->data.end(), val); } + /*=======================================================================*/ + std::string toString() const + { + std::stringstream text; + for (size_type x2 = 0; x2 < this->nx2; x2++) { + for (size_type x1 = 0; x1 < this->nx1; x1++) { + // hier kommts zum Konflikt ab und an ... + text << this->getObject(x1, x2) << ", "; + } + text << "\n"; + } - return text.str(); - } - /*=======================================================================*/ - std::string getInfo() const - { - std::stringstream text; - text<<"CbArray2D< storageType="<<typeid(T).name()<<", indexer="<<typeid(IndexClass).name()<<" >"; - text<<"( nx1="<<this->nx1<<", nx2="<<this->nx2<<")"; - return text.str(); - } - /*=======================================================================*/ - void resize(const size_type& uniformDimensionSize) - { - this->resize(uniformDimensionSize,uniformDimensionSize); - } - /*=======================================================================*/ - void resize(const size_type& nx1,const size_type& nx2) - { - this->nx1 = nx1; - this->nx2 = nx2; - this->data.resize(nx1*nx2); - } - /*=======================================================================*/ - void resize(const size_type& nx1, const size_type& nx2, const value_type& initVal ) - { - this->nx1 = nx1; - this->nx2 = nx2; - this->data.resize(nx1*nx2,initVal); - } - /*=======================================================================*/ - void clear() - { - this->nx1 = 0; - this->nx2 = 0; - this->data.clear(); - } - /*=======================================================================*/ - std::vector< value_type >& getDataVector() { return this->data; } - /*=======================================================================*/ - const std::vector< value_type >& getDataVector() const { return this->data; } - /*=======================================================================*/ - inline size_type getDataVectorIndex(const size_type& x1, const size_type& x2) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2)) ); - #endif + return text.str(); + } + /*=======================================================================*/ + std::string getInfo() const + { + std::stringstream text; + text << "CbArray2D< storageType=" << typeid(T).name() << ", indexer=" << typeid(IndexClass).name() << " >"; + text << "( nx1=" << this->nx1 << ", nx2=" << this->nx2 << ")"; + return text.str(); + } + /*=======================================================================*/ + void resize(const size_type &uniformDimensionSize) { this->resize(uniformDimensionSize, uniformDimensionSize); } + /*=======================================================================*/ + void resize(const size_type &nx1, const size_type &nx2) + { + this->nx1 = nx1; + this->nx2 = nx2; + this->data.resize(nx1 * nx2); + } + /*=======================================================================*/ + void resize(const size_type &nx1, const size_type &nx2, const value_type &initVal) + { + this->nx1 = nx1; + this->nx2 = nx2; + this->data.resize(nx1 * nx2, initVal); + } + /*=======================================================================*/ + void clear() + { + this->nx1 = 0; + this->nx2 = 0; + this->data.clear(); + } + /*=======================================================================*/ + std::vector<value_type> &getDataVector() { return this->data; } + /*=======================================================================*/ + const std::vector<value_type> &getDataVector() const { return this->data; } + /*=======================================================================*/ + inline size_type getDataVectorIndex(const size_type &x1, const size_type &x2) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2))); +#endif - return indexer.getIndex(x1,x2,nx1,nx2); - } + return indexer.getIndex(x1, x2, nx1, nx2); + } protected: - /*=======================================================================*/ - //success -> true - //else -> false - inline bool indicesInRange(const size_type& x1, const size_type& x2) const - { - if( x1 < 0 || x1 >= this->nx1 - || x2 < 0 || x2 >= this->nx2 ) - { - return false; - } - return true; - } - /*=======================================================================*/ - std::string getExceptionErrorString(const size_type& x1, const size_type& x2) const - { - std::stringstream out("index out of range - "); - out<<"("<<x1<<","<<x2<<") not in ("<<nx1<<","<<nx2<<")"; - return out.str(); - } - /*=======================================================================*/ + /*=======================================================================*/ + // success -> true + // else -> false + inline bool indicesInRange(const size_type &x1, const size_type &x2) const + { + if (x1 < 0 || x1 >= this->nx1 || x2 < 0 || x2 >= this->nx2) { + return false; + } + return true; + } + /*=======================================================================*/ + std::string getExceptionErrorString(const size_type &x1, const size_type &x2) const + { + std::stringstream out("index out of range - "); + out << "(" << x1 << "," << x2 << ") not in (" << nx1 << "," << nx2 << ")"; + return out.str(); + } + /*=======================================================================*/ protected: - size_type nx1; - size_type nx2; - indexer_type indexer; - std::vector< value_type > data; + size_type nx1; + size_type nx2; + indexer_type indexer; + std::vector<value_type> data; }; -#endif //CBARRAY2D_H +#endif // CBARRAY2D_H diff --git a/src/basics/basics/container/CbArray3D.h b/src/basics/basics/container/CbArray3D.h index 103cc6110..f7fb495f7 100644 --- a/src/basics/basics/container/CbArray3D.h +++ b/src/basics/basics/container/CbArray3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,90 +35,97 @@ #include <iomanip> -#include <basics/utilities/UbException.h> -#include <basics/utilities/UbEqual.h> +#include "PointerDefinitions.h" #include <algorithm> +#include <basics/utilities/UbEqual.h> +#include <basics/utilities/UbException.h> #include <typeinfo> -#include "PointerDefinitions.h" ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // IndexClasses -//IndexerX3X2X1: +// IndexerX3X2X1: // 4 5 6 10 11 12 // Array ebene A 1 2 3 ebene B 7 8 9 --> vector 1 2 3 4 5 6 7 8 9 10 11 12 -//x1-reihen "liegen am stueck" im speicher -//optimaler schleifendurchlauf -//for(alle X3) +// x1-reihen "liegen am stueck" im speicher +// optimaler schleifendurchlauf +// for(alle X3) // for(alle X2) // for(alle X1) -class IndexerX3X2X1// FunctorX1SortedForX1X2Plane +class IndexerX3X2X1 // FunctorX1SortedForX1X2Plane { public: - using size_type = size_t; + using size_type = size_t; + public: - inline std::size_t getIndex( const size_type& x1 , const size_type& x2 , const size_type& x3 - , const size_type& nx1, const size_type& nx2, const size_type& /*nx3*/ ) const - { - return nx1 * ( nx2 * x3 + x2) + x1 ; - } - inline std::size_t getStartIndexOfSortedArray( const size_type& /*x1*/ , const size_type& x2 , const size_type& x3 - , const size_type& nx1, const size_type& nx2, const size_type& /*nx3*/ ) const - { - return nx1 * ( nx2 * x3 + x2); - } + inline std::size_t getIndex(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &nx1, + const size_type &nx2, const size_type & /*nx3*/) const + { + return nx1 * (nx2 * x3 + x2) + x1; + } + inline std::size_t getStartIndexOfSortedArray(const size_type & /*x1*/, const size_type &x2, const size_type &x3, + const size_type &nx1, const size_type &nx2, + const size_type & /*nx3*/) const + { + return nx1 * (nx2 * x3 + x2); + } }; -//IndexerX1X2X3: +// IndexerX1X2X3: // 4 5 6 10 11 12 // Array ebene A 1 2 3 ebene B 7 8 9 --> -//optimaler schleifendurchlauf -//for(alle X1) +// optimaler schleifendurchlauf +// for(alle X1) // for(alle X2) // for(alle X3) -class IndexerX1X2X3 //FunctorX3SortedForX3X2Plane +class IndexerX1X2X3 // FunctorX3SortedForX3X2Plane { public: - using size_type = size_t; + using size_type = size_t; + public: - inline std::size_t getIndex( const size_type& x1 , const size_type& x2 , const size_type& x3 - , const size_type& /*nx1*/, const size_type& nx2, const size_type& nx3 ) const - { - return nx3 * ( nx2 * x1 + x2) + x3 ; - } - inline std::size_t getStartIndexOfSortedArray( const size_type& x1 , const size_type& x2 , const size_type& /*x3*/ - , const size_type& /*nx1*/, const size_type& nx2, const size_type& nx3 ) const - { - return nx3 * ( nx2 * x1 + x2); - } + inline std::size_t getIndex(const size_type &x1, const size_type &x2, const size_type &x3, + const size_type & /*nx1*/, const size_type &nx2, const size_type &nx3) const + { + return nx3 * (nx2 * x1 + x2) + x3; + } + inline std::size_t getStartIndexOfSortedArray(const size_type &x1, const size_type &x2, const size_type & /*x3*/ + , + const size_type & /*nx1*/, const size_type &nx2, + const size_type &nx3) const + { + return nx3 * (nx2 * x1 + x2); + } }; -//IndexerX2X1X3: +// IndexerX2X1X3: // 4 5 6 10 11 12 // Array ebene A 1 2 3 ebene B 7 8 9 --> vector 1 7 2 8 3 9 4 10 5 11 6 12 -//optimaler schleifendurchlauf -//for(alle X2) +// optimaler schleifendurchlauf +// for(alle X2) // for(alle X1) // for(alle X3) class IndexerX2X1X3 { public: - using size_type = size_t; + using size_type = size_t; + public: - inline std::size_t getIndex( const size_type& x1 , const size_type& x2 , const size_type& x3 - , const size_type& nx1, const size_type& /*nx2*/, const size_type& nx3 ) const - { - return nx3* ( nx1 * x2 + x1) + x3 ; - } - inline std::size_t getStartIndexOfSortedArray( const size_type& x1 , const size_type& x2 , const size_type& /*x3*/ - , const size_type& nx1, const size_type& /*nx2*/, const size_type& nx3 ) const - { - return nx3* ( nx1 * x2 + x1); - } + inline std::size_t getIndex(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &nx1, + const size_type & /*nx2*/, const size_type &nx3) const + { + return nx3 * (nx1 * x2 + x1) + x3; + } + inline std::size_t getStartIndexOfSortedArray(const size_type &x1, const size_type &x2, const size_type & /*x3*/ + , + const size_type &nx1, const size_type & /*nx2*/, + const size_type &nx3) const + { + return nx3 * (nx1 * x2 + x1); + } }; - ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // CbArray3D @@ -132,334 +139,307 @@ public: //! //! -release: not defined "NO_CB_RANGECHECK" && defined "CB_RANGECHECK" ////////////////////////////////////////////////////////////////////////// -template<typename T, typename IndexClass = IndexerX3X2X1> +template <typename T, typename IndexClass = IndexerX3X2X1> class CbArray3D { public: - using CbArray3DPtr = SPtr<CbArray3D<T, IndexClass> >; + using CbArray3DPtr = SPtr<CbArray3D<T, IndexClass>>; - using value_type = T; - using indexer_type = IndexClass; - using size_type = typename IndexClass::size_type; - using reference = typename std::vector<value_type>::reference; - using const_reference = typename std::vector<value_type>::const_reference; - using pointer = typename std::vector<value_type>::pointer; - using const_pointer = typename std::vector<value_type>::const_pointer; + using value_type = T; + using indexer_type = IndexClass; + using size_type = typename IndexClass::size_type; + using reference = typename std::vector<value_type>::reference; + using const_reference = typename std::vector<value_type>::const_reference; + using pointer = typename std::vector<value_type>::pointer; + using const_pointer = typename std::vector<value_type>::const_pointer; private: - template< typename value_type2, typename IndexClass2 > friend class CbArray3D; + template <typename value_type2, typename IndexClass2> + friend class CbArray3D; public: - /*=======================================================================*/ - CbArray3D() - { - this->resize(0,0,0); - } - /*=======================================================================*/ - CbArray3D(const size_type& nx1,const size_type& nx2, const size_type& nx3, const value_type& val) - { - this->resize(nx1,nx2,nx3,val); - } - /*=======================================================================*/ - CbArray3D(const size_type& nx1,const size_type& nx2, const size_type& nx3) + /*=======================================================================*/ + CbArray3D() { this->resize(0, 0, 0); } + /*=======================================================================*/ + CbArray3D(const size_type &nx1, const size_type &nx2, const size_type &nx3, const value_type &val) { - this->resize(nx1,nx2,nx3); + this->resize(nx1, nx2, nx3, val); + } + /*=======================================================================*/ + CbArray3D(const size_type &nx1, const size_type &nx2, const size_type &nx3) { this->resize(nx1, nx2, nx3); } + /*=======================================================================*/ + CbArray3D(const size_type &uniformDimensionSize /*nx1==nx2==nx3*/) + { + this->resize(uniformDimensionSize, uniformDimensionSize, uniformDimensionSize); + } + /*=======================================================================*/ + // ssbernimmt vector als daten vector! (erstellt KEINE kopie!!!, vec ist anschliessend leer, da swap verwendet wird) + CbArray3D(std::vector<value_type> &vec, const size_type &nx1, const size_type &nx2, const size_type &nx3) + { + assert((nx1 * nx2 * nx3) == vec.size()); + this->data.swap(vec); + this->resize(nx1, nx2, nx3); + } + /*=======================================================================*/ + CbArray3D(const CbArray3D &src) : nx1(src.nx1), nx2(src.nx2), nx3(src.nx3), data(src.data) {} + /*=======================================================================*/ + template <typename value_type2> + CbArray3D(const CbArray3D<value_type2> &src) : nx1(src.nx1), nx2(src.nx2), nx3(src.nx3) + { + // Sourcedaten kopieren + this->data.resize(src.data.size()); + for (std::size_t i = 0; i < data.size(); ++i) + this->data[i] = src.data[i]; + } + /*=======================================================================*/ + virtual ~CbArray3D() = default; + /*=======================================================================*/ + CbArray3D &operator=(const CbArray3D &rhs) + { + if (this == &rhs) + return *this; + + this->nx1 = rhs.nx1; + this->nx2 = rhs.nx2; + this->nx3 = rhs.nx3; + + // gespeicherte Datenelemente loeschen + // Laenge anpassen + this->data.resize(rhs.data.size()); + // gespeicherte Datenelemente loeschen + this->data.clear(); + + // Sourcedaten kopieren + this->data = rhs.data; + + return *this; + } + /*=======================================================================*/ + // durch value_type2 kann man z.B. ein float array einer double array zuweisen! + template <typename value_type2, typename IndexClass2> + CbArray3D &operator=(const CbArray3D<value_type2, IndexClass2> &rhs) + { + this->nx1 = rhs.nx1; + this->nx2 = rhs.nx2; + this->nx3 = rhs.nx3; + + // gespeicherte Datenelemente loeschen + this->data.clear(); + // Laenge anpassen + this->data.resize(rhs.data.size()); + + // Sourcedaten kopieren (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) + for (int x3 = 0; x3 < this->nx3; x3++) + for (int x2 = 0; x2 < this->nx2; x2++) + for (int x1 = 0; x1 < this->nx1; x1++) + this->operator()(x1, x2, x3) = static_cast<value_type>(rhs.operator()(x1, x2, x3)); + + return *this; + } + /*=======================================================================*/ + bool operator==(const CbArray3D &rhs) const + { + if (this == &rhs) + return true; + + if (this->nx1 != rhs.nx1 || this->nx2 != rhs.nx2 || this->nx3 != rhs.nx3 || + this->data.size() != rhs.data.size()) { + return false; + } + + return std::equal(this->data.begin(), this->data.end(), rhs.data.begin(), UbEqual<value_type, value_type>()); + } + /*=======================================================================*/ + template <typename value_type2, typename IndexClass2> + bool operator==(const CbArray3D<value_type2, IndexClass2> &rhs) const + { + if (this->data.size() != rhs.data.size()) + return false; + + // Sourcedaten einzeln checken (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) + for (int x3 = 0; x3 < this->nx3; x3++) + for (int x2 = 0; x2 < this->nx2; x2++) + for (int x1 = 0; x1 < this->nx1; x1++) + if (!isUbEqual(this->operator()(x1, x2, x3), rhs.operator()(x1, x2, x3))) + return false; + + return true; + } + /*=======================================================================*/ + bool operator!=(const CbArray3D &src) const { return !(*this == src); } + /*=======================================================================*/ + template <typename value_type2, typename IndexClass2> + bool operator!=(const CbArray3D<value_type2, IndexClass2> &rhs) const + { + return !(*this == rhs); + } + /*=======================================================================*/ + reference operator()(const size_type &x1, const size_type &x2, const size_type &x3) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3))); +#endif + + return this->data[indexer.getIndex(x1, x2, x3, nx1, nx2, nx3)]; + } + /*=======================================================================*/ + const_reference operator()(const size_type &x1, const size_type &x2, const size_type &x3) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3))); +#endif + + return this->data[indexer.getIndex(x1, x2, x3, nx1, nx2, nx3)]; + } + /*=======================================================================*/ + pointer getStartAdressOfSortedArray(const size_type &x1, const size_type &x2, const size_type &x3) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3))); +#endif + + return &this->data[indexer.getStartIndexOfSortedArray(x1, x2, x3, nx1, nx2, nx3)]; + } + /*=======================================================================*/ + const_pointer getStartAdressOfSortedArray(const size_type &x1, const size_type &x2, const size_type &x3) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3))); +#endif + + return &this->data[indexer.getStartIndexOfSortedArray(x1, x2, x3, nx1, nx2, nx3)]; + } + /*=======================================================================*/ + void setObject(const size_type &x1, const size_type &x2, const size_type &x3, const value_type &value) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3))); +#endif + + this->data[indexer.getIndex(x1, x2, x3, nx1, nx2, nx3)] = value; + } + /*=======================================================================*/ + reference getObject(const size_type &x1, const size_type &x2, const size_type &x3) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3))); +#endif + + return this->data[indexer.getIndex(x1, x2, x3, nx1, nx2, nx3)]; + } + /*=======================================================================*/ + const_reference getObject(const size_type &x1, const size_type &x2, const size_type &x3) const + { + return (*this)(x1, x2, x3); + } + /*=======================================================================*/ + bool isEmpty() const { return data.empty(); } + size_type getNX1() const { return this->nx1; } + size_type getNX2() const { return this->nx2; } + size_type getNX3() const { return this->nx3; } + /*=======================================================================*/ + void reset(const value_type &val) { std::fill(this->data.begin(), this->data.end(), val); } + /*=======================================================================*/ + std::string toString() const + { + std::stringstream text; + for (size_type x1 = 0; x1 < this->nx1; x1++) { + for (size_type x2 = 0; x2 < this->nx2; x2++) { + for (size_type x3 = 0; x3 < this->nx3; x3++) { + text << (*this)(x1, x2, x3) << ", "; + } + text << std::endl; + } + text << std::endl << std::endl; + } + + return text.str(); + } + /*=======================================================================*/ + std::string getInfo() const + { + std::stringstream text; + text << "CbArray3D< storageType=" << typeid(T).name() << ", indexer=" << typeid(IndexClass).name() << " >"; + text << "( nx1=" << this->nx1 << ", nx2=" << this->nx2 << ", nx3=" << this->nx3 << ")"; + return text.str(); + } + /*=======================================================================*/ + void resize(const int &uniformDimensionSize) + { + this->resize(uniformDimensionSize, uniformDimensionSize, uniformDimensionSize); + } + /*=======================================================================*/ + void resize(const size_type &nx1, const size_type &nx2, const size_type &nx3) + { + this->nx1 = nx1; + this->nx2 = nx2; + this->nx3 = nx3; + this->data.resize(nx1 * nx2 * nx3); + } + /*=======================================================================*/ + void resize(const size_type &nx1, const size_type &nx2, const size_type &nx3, const value_type &val) + { + this->nx1 = nx1; + this->nx2 = nx2; + this->nx3 = nx3; + this->data.resize(nx1 * nx2 * nx3, val); + } + /*=======================================================================*/ + void clear() + { + this->nx1 = 0; + this->nx2 = 0; + this->nx3 = 0; + this->data.clear(); + } + /*=======================================================================*/ + std::vector<value_type> &getDataVector() { return this->data; } + /*=======================================================================*/ + const std::vector<value_type> &getDataVector() const { return this->data; } + /*=======================================================================*/ + inline std::size_t getDataVectorIndex(const size_type &x1, const size_type &x2, const size_type &x3) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3))); +#endif + + return indexer.getIndex(x1, x2, x3, nx1, nx2, nx3); + } + + /*=======================================================================*/ + // success -> true + // else -> false + inline bool indicesInRange(const size_type &x1, const size_type &x2, const size_type &x3) const + { + if (x1 < 0 || x1 >= this->nx1 || x2 < 0 || x2 >= this->nx2 || x3 < 0 || x3 >= this->nx3) { + return false; + } + return true; } - /*=======================================================================*/ - CbArray3D(const size_type& uniformDimensionSize /*nx1==nx2==nx3*/) - { - this->resize(uniformDimensionSize,uniformDimensionSize,uniformDimensionSize); - } - /*=======================================================================*/ - //ssbernimmt vector als daten vector! (erstellt KEINE kopie!!!, vec ist anschliessend leer, da swap verwendet wird) - CbArray3D(std::vector<value_type>& vec, const size_type& nx1,const size_type& nx2, const size_type& nx3) - { - assert( (nx1*nx2*nx3)==vec.size() ); - this->data.swap(vec); - this->resize(nx1,nx2,nx3); - } - /*=======================================================================*/ - CbArray3D(const CbArray3D& src) - : nx1(src.nx1) - , nx2(src.nx2) - , nx3(src.nx3) - , data(src.data) - { - } - /*=======================================================================*/ - template< typename value_type2 > - CbArray3D(const CbArray3D< value_type2 >& src) - : nx1(src.nx1) - , nx2(src.nx2) - , nx3(src.nx3) - { - //Sourcedaten kopieren - this->data.resize( src.data.size() ); - for(std::size_t i=0; i<data.size(); ++i) - this->data[i] = src.data[i]; - } - /*=======================================================================*/ - virtual ~CbArray3D() = default; - /*=======================================================================*/ - CbArray3D& operator= (const CbArray3D& rhs) - { - if(this == &rhs) return *this; - - this->nx1 = rhs.nx1; - this->nx2 = rhs.nx2; - this->nx3 = rhs.nx3; - - //gespeicherte Datenelemente loeschen - //Laenge anpassen - this->data.resize(rhs.data.size()); - //gespeicherte Datenelemente loeschen - this->data.clear(); - - //Sourcedaten kopieren - this->data = rhs.data; - - return *this; - } - /*=======================================================================*/ - //durch value_type2 kann man z.B. ein float array einer double array zuweisen! - template< typename value_type2, typename IndexClass2 > - CbArray3D& operator= (const CbArray3D< value_type2, IndexClass2 >& rhs) - { - this->nx1 = rhs.nx1; - this->nx2 = rhs.nx2; - this->nx3 = rhs.nx3; - - //gespeicherte Datenelemente loeschen - this->data.clear(); - //Laenge anpassen - this->data.resize(rhs.data.size()); - - //Sourcedaten kopieren (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) - for(int x3=0; x3<this->nx3; x3++) - for(int x2=0; x2<this->nx2; x2++) - for(int x1=0; x1<this->nx1; x1++) - this->operator()(x1,x2,x3) = static_cast< value_type >( rhs.operator()(x1,x2,x3) ); - - return *this; - } - /*=======================================================================*/ - bool operator== (const CbArray3D& rhs) const - { - if(this == &rhs) return true; - - if( this->nx1!=rhs.nx1 - || this->nx2!=rhs.nx2 - || this->nx3!=rhs.nx3 - || this->data.size() != rhs.data.size() ) - { - return false; - } - - return std::equal( this->data.begin(), this->data.end(), rhs.data.begin(), UbEqual<value_type, value_type >() ); - } - /*=======================================================================*/ - template< typename value_type2, typename IndexClass2 > - bool operator== (const CbArray3D< value_type2, IndexClass2 >& rhs) const - { - if( this->data.size() != rhs.data.size() ) return false; - - //Sourcedaten einzeln checken (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) - for(int x3=0; x3<this->nx3; x3++) - for(int x2=0; x2<this->nx2; x2++) - for(int x1=0; x1<this->nx1; x1++) - if( !isUbEqual(this->operator()(x1,x2,x3), rhs.operator()(x1,x2,x3)) ) - return false; - - return true; - } - /*=======================================================================*/ - bool operator!= (const CbArray3D& src) const - { - return !(*this==src); - } - /*=======================================================================*/ - template< typename value_type2, typename IndexClass2 > - bool operator!= (const CbArray3D< value_type2, IndexClass2 >& rhs) const - { - return !(*this==rhs); - } - /*=======================================================================*/ - reference operator() (const size_type& x1, const size_type& x2, const size_type& x3) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3)) ); - #endif - - return this->data[ indexer.getIndex(x1,x2,x3,nx1,nx2,nx3) ]; - } - /*=======================================================================*/ - const_reference operator() (const size_type& x1, const size_type& x2, const size_type& x3) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3)) ); - #endif - - return this->data[ indexer.getIndex(x1,x2,x3,nx1,nx2,nx3) ]; - } - /*=======================================================================*/ - pointer getStartAdressOfSortedArray(const size_type& x1, const size_type& x2, const size_type& x3) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3)) ); - #endif - - return &this->data[indexer.getStartIndexOfSortedArray(x1,x2,x3,nx1,nx2,nx3)]; - } - /*=======================================================================*/ - const_pointer getStartAdressOfSortedArray(const size_type& x1, const size_type& x2, const size_type& x3) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3)) ); - #endif - - return &this->data[indexer.getStartIndexOfSortedArray(x1,x2,x3,nx1,nx2,nx3)]; - } - /*=======================================================================*/ - void setObject(const size_type& x1, const size_type& x2, const size_type& x3, const value_type& value) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3)) ); - #endif - - this->data[ indexer.getIndex(x1,x2,x3,nx1,nx2,nx3) ] = value; - } - /*=======================================================================*/ - reference getObject(const size_type& x1, const size_type& x2, const size_type& x3) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3)) ); - #endif - - return this->data[ indexer.getIndex(x1,x2,x3,nx1,nx2,nx3) ] ; - } - /*=======================================================================*/ - const_reference getObject(const size_type& x1, const size_type& x2, const size_type& x3) const - { - return (*this)(x1,x2,x3); - } - /*=======================================================================*/ - bool isEmpty() const { return data.empty(); } - size_type getNX1() const { return this->nx1; } - size_type getNX2() const { return this->nx2; } - size_type getNX3() const { return this->nx3; } - /*=======================================================================*/ - void reset(const value_type& val) - { - std::fill( this->data.begin(), this->data.end(), val ); - } - /*=======================================================================*/ - std::string toString() const - { - std::stringstream text; - for(size_type x1=0; x1<this->nx1; x1++) - { - for(size_type x2=0; x2<this->nx2; x2++) - { - for(size_type x3=0; x3<this->nx3; x3++) - { - text<<(*this)(x1,x2,x3)<<", "; - } - text<<std::endl; - } - text<<std::endl<<std::endl; - } - - return text.str(); - } - /*=======================================================================*/ - std::string getInfo() const - { - std::stringstream text; - text<<"CbArray3D< storageType="<<typeid(T).name()<<", indexer="<<typeid(IndexClass).name()<<" >"; - text<<"( nx1="<<this->nx1<<", nx2="<<this->nx2<<", nx3="<<this->nx3<<")"; - return text.str(); - } - /*=======================================================================*/ - void resize(const int& uniformDimensionSize) - { - this->resize(uniformDimensionSize,uniformDimensionSize,uniformDimensionSize); - } - /*=======================================================================*/ - void resize(const size_type& nx1,const size_type& nx2, const size_type& nx3) - { - this->nx1 = nx1; - this->nx2 = nx2; - this->nx3 = nx3; - this->data.resize(nx1*nx2*nx3); - } - /*=======================================================================*/ - void resize(const size_type& nx1,const size_type& nx2, const size_type& nx3,const value_type& val) - { - this->nx1 = nx1; - this->nx2 = nx2; - this->nx3 = nx3; - this->data.resize(nx1*nx2*nx3,val); - } - /*=======================================================================*/ - void clear() - { - this->nx1 = 0; - this->nx2 = 0; - this->nx3 = 0; - this->data.clear(); - } - /*=======================================================================*/ - std::vector< value_type >& getDataVector() { return this->data; } - /*=======================================================================*/ - const std::vector< value_type >& getDataVector() const { return this->data; } - /*=======================================================================*/ - inline std::size_t getDataVectorIndex(const size_type& x1, const size_type& x2, const size_type& x3) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3)) ); - #endif - - return indexer.getIndex(x1,x2,x3,nx1,nx2,nx3); - } - - - /*=======================================================================*/ - //success -> true - //else -> false - inline bool indicesInRange(const size_type& x1, const size_type& x2, const size_type& x3) const - { - if( x1 < 0 || x1 >= this->nx1 - || x2 < 0 || x2 >= this->nx2 - || x3 < 0 || x3 >= this->nx3 ) - { - return false; - } - return true; - } -protected: - /*=======================================================================*/ - std::string getExceptionErrorString(const size_type& x1, const size_type& x2, const size_type& x3) const - { - std::stringstream out("index out of range - "); - out<<"("<<x1<<","<<x2<<","<<x3<<") not in ("<<nx1<<","<<nx2<<","<<nx3<<")"; - return out.str(); - } - /*=======================================================================*/ protected: - size_type nx1; - size_type nx2; - size_type nx3; - indexer_type indexer; - std::vector< value_type > data; + /*=======================================================================*/ + std::string getExceptionErrorString(const size_type &x1, const size_type &x2, const size_type &x3) const + { + std::stringstream out("index out of range - "); + out << "(" << x1 << "," << x2 << "," << x3 << ") not in (" << nx1 << "," << nx2 << "," << nx3 << ")"; + return out.str(); + } + /*=======================================================================*/ +protected: + size_type nx1; + size_type nx2; + size_type nx3; + indexer_type indexer; + std::vector<value_type> data; }; -#endif //CBARRAY3D_H +#endif // CBARRAY3D_H diff --git a/src/basics/basics/container/CbArray4D.h b/src/basics/basics/container/CbArray4D.h index 16c554232..31238e1b8 100644 --- a/src/basics/basics/container/CbArray4D.h +++ b/src/basics/basics/container/CbArray4D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,67 +33,73 @@ #ifndef CBARRAY4D_H #define CBARRAY4D_H - - -#include <iomanip> -#include <basics/utilities/UbException.h> -#include <basics/utilities/UbEqual.h> +#include "PointerDefinitions.h" #include <algorithm> +#include <basics/utilities/UbEqual.h> +#include <basics/utilities/UbException.h> +#include <iomanip> #include <typeinfo> -#include "PointerDefinitions.h" ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // IndexClasses -//IndexerX1X2X3X4: -//x4-reihen "liegen am stueck" im speicher -//optimaler schleifendurchlauf -//for(alle X1) +// IndexerX1X2X3X4: +// x4-reihen "liegen am stueck" im speicher +// optimaler schleifendurchlauf +// for(alle X1) // for(alle X2) // for(alle X3) // for(alle X4) class IndexerX1X2X3X4 { public: - using size_type = int; + using size_type = int; + public: - inline std::size_t getIndex( const size_type& x1 , const size_type& x2 , const size_type& x3 , const size_type& x4 - , const size_type& /*nx1*/, const size_type& nx2, const size_type& nx3, const size_type& nx4 ) const - { - return nx4*(nx3*(nx2*x1+ x2)+x3)+x4 ; - } - inline std::size_t getStartIndexOfSortedArray( const size_type& x1 , const size_type& x2 , const size_type& x3 , const size_type& /*x4*/ - , const size_type& /*nx1*/, const size_type& nx2, const size_type& nx3, const size_type& nx4 ) const - { - return nx4*(nx3*(nx2*x1+ x2)+x3); - } + inline std::size_t getIndex(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4, + const size_type & /*nx1*/, const size_type &nx2, const size_type &nx3, + const size_type &nx4) const + { + return nx4 * (nx3 * (nx2 * x1 + x2) + x3) + x4; + } + inline std::size_t getStartIndexOfSortedArray(const size_type &x1, const size_type &x2, const size_type &x3, + const size_type & /*x4*/ + , + const size_type & /*nx1*/, const size_type &nx2, const size_type &nx3, + const size_type &nx4) const + { + return nx4 * (nx3 * (nx2 * x1 + x2) + x3); + } }; ////////////////////////////////////////////////////////////////////////// // IndexClasses -//IndexerX4X3X2X1: -//x1-reihen "liegen am stueck" im speicher -//optimaler schleifendurchlauf -//for(alle X4) +// IndexerX4X3X2X1: +// x1-reihen "liegen am stueck" im speicher +// optimaler schleifendurchlauf +// for(alle X4) // for(alle X3) // for(alle X2) // for(alle X1) class IndexerX4X3X2X1 { public: - using size_type = size_t; + using size_type = size_t; + public: - inline std::size_t getIndex( const size_type& x1 , const size_type& x2 , const size_type& x3 , const size_type& x4 - , const size_type& nx1, const size_type& nx2, const size_type& nx3, const size_type& /*nx4*/ ) const - { - return nx1*(nx2*(nx3*x4+ x3)+x2)+x1; - } - inline std::size_t getStartIndexOfSortedArray( const size_type& /*x1*/ , const size_type& x2 , const size_type& x3 , const size_type& x4 - , const size_type& nx1, const size_type& nx2, const size_type& nx3, const size_type& /*nx4*/ ) const - { - return nx1*(nx2*(nx3*x4+ x3)+x2); - } + inline std::size_t getIndex(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4, + const size_type &nx1, const size_type &nx2, const size_type &nx3, + const size_type & /*nx4*/) const + { + return nx1 * (nx2 * (nx3 * x4 + x3) + x2) + x1; + } + inline std::size_t getStartIndexOfSortedArray(const size_type & /*x1*/, const size_type &x2, const size_type &x3, + const size_type &x4, const size_type &nx1, const size_type &nx2, + const size_type &nx3, const size_type & /*nx4*/) const + { + return nx1 * (nx2 * (nx3 * x4 + x3) + x2); + } }; ////////////////////////////////////////////////////////////////////////// // CbArray4D @@ -106,343 +112,327 @@ public: //! //! -release: not defined "NO_CB_RANGECHECK" && defined "CB_RANGECHECK" ////////////////////////////////////////////////////////////////////////// -template<typename T, typename IndexClass = IndexerX4X3X2X1> +template <typename T, typename IndexClass = IndexerX4X3X2X1> class CbArray4D { public: - using CbArray4DPtr = SPtr<CbArray4D<T, IndexClass> >; + using CbArray4DPtr = SPtr<CbArray4D<T, IndexClass>>; - using value_type = T; - using indexer_type = IndexClass; - using size_type = typename IndexClass::size_type; - using reference = typename std::vector<value_type>::reference; - using const_reference = typename std::vector<value_type>::const_reference; - using pointer = typename std::vector<value_type>::pointer; - using const_pointer = typename std::vector<value_type>::const_pointer; + using value_type = T; + using indexer_type = IndexClass; + using size_type = typename IndexClass::size_type; + using reference = typename std::vector<value_type>::reference; + using const_reference = typename std::vector<value_type>::const_reference; + using pointer = typename std::vector<value_type>::pointer; + using const_pointer = typename std::vector<value_type>::const_pointer; private: - template< typename value_type2, typename IndexClass2 > friend class CbArray4D; + template <typename value_type2, typename IndexClass2> + friend class CbArray4D; public: - /*=======================================================================*/ - CbArray4D() - { - this->resize(0,0,0,0); - } - /*=======================================================================*/ - CbArray4D(const size_type& nx1,const size_type& nx2, const size_type& nx3, const size_type& nx4) - { - this->resize(nx1,nx2,nx3,nx4); - } - /*=======================================================================*/ - CbArray4D(const size_type& nx1,const size_type& nx2, const size_type& nx3, const size_type& nx4, const value_type& val) - { - this->resize(nx1,nx2,nx3,nx4,val); - } - /*=======================================================================*/ - CbArray4D(const size_type& uniformDimensionSize /*nx1=nx2=nx3=nx4*/) - { - this->resize(uniformDimensionSize,uniformDimensionSize,uniformDimensionSize,uniformDimensionSize); - } - /*=======================================================================*/ - //ubernimmt vector als daten vector! (erstellt KEINE kopie!!!, vec ist anschliessend leer, da swap verwendet wird) - CbArray4D(std::vector<value_type>& vec, const size_type& nx1,const size_type& nx2, const size_type& nx3, const size_type& nx4) - { - assert( (nx1*nx2*nx3*nx4)==vec.size() ); - this->data.swap(vec); - this->resize(nx1,nx2,nx3,nx4); - } - /*=======================================================================*/ - CbArray4D(const CbArray4D& src) - : nx1(src.nx1) - , nx2(src.nx2) - , nx3(src.nx3) - , nx4(src.nx4) - , data(src.data) - { - } - /*=======================================================================*/ - template< typename value_type2 > - CbArray4D(const CbArray4D< value_type2 >& src) - : nx1(src.nx1) - , nx2(src.nx2) - , nx3(src.nx3) - , nx4(src.nx4) - { - //Sourcedaten kopieren - this->data.resize( src.data.size() ); - for(std::size_t i=0; i<data.size(); ++i) - this->data[i] = src.data[i]; - } - /*=======================================================================*/ - virtual ~CbArray4D()= default; - /*=======================================================================*/ - CbArray4D& operator= (const CbArray4D& rhs) - { - if(this == &rhs) return *this; - - this->nx1 = rhs.nx1; - this->nx2 = rhs.nx2; - this->nx3 = rhs.nx3; - this->nx4 = rhs.nx4; - - //gespeicherte Datenelemente loeschen - //Laenge anpassen - this->data.resize(rhs.data.size()); - //gespeicherte Datenelemente loeschen - this->data.clear(); - - //Sourcedaten kopieren - this->data = rhs.data; - - return *this; - } - /*=======================================================================*/ - //durch value_type2 kann man z.B. ein float Array einem double Array zuweisen! - template< typename value_type2, typename IndexClass2 > - CbArray4D& operator= (const CbArray4D< value_type2, IndexClass2 >& rhs) - { - this->nx1 = rhs.nx1; - this->nx2 = rhs.nx2; - this->nx3 = rhs.nx3; - this->nx4 = rhs.nx4; - - //gespeicherte Datenelemente loeschen - this->data.clear(); - //Laenge anpassen - this->data.resize(rhs.data.size()); - - //Sourcedaten kopieren (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) - for(int x1=0; x1<this->nx1; x1++) - for(int x2=0; x2<this->nx2; x2++) - for(int x3=0; x3<this->nx3; x3++) - for(int x4=0; x4<this->nx4; x4++) - this->operator()(x1,x2,x3,x4) = static_cast< value_type >( rhs.operator()(x1,x2,x3,x4)); - - return *this; - } - /*=======================================================================*/ - bool operator== (const CbArray4D& rhs) const - { - if( this == &rhs ) return true; - - if( this->nx1!=rhs.nx1 - || this->nx2!=rhs.nx2 - || this->nx3!=rhs.nx3 - || this->nx4!=rhs.nx4 - || this->data.size() != rhs.data.size() ) - { - return false; - } - - return std::equal( this->data.begin(), this->data.end(), rhs.data.begin(), UbEqual<value_type, value_type >() ); - } - /*=======================================================================*/ - template< typename value_type2, typename IndexClass2 > - bool operator== (const CbArray4D< value_type2, IndexClass2 >& rhs) const - { - if( this->data.size() != rhs.data.size() ) return false; - - //Sourcedaten einzeln checken (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) - for(int x4=0; x4<this->nx4; x4++) - for(int x3=0; x3<this->nx3; x3++) - for(int x2=0; x2<this->nx2; x2++) - for(int x1=0; x1<this->nx1; x1++) - if( !isUbEqual(this->operator()(x1,x2,x3,x4), rhs.operator()(x1,x2,x3,x4)) ) - return false; - - return true; - } - /*=======================================================================*/ - bool operator!= (const CbArray4D& rhs) const - { - return !(*this==rhs); - } - /*=======================================================================*/ - template< typename value_type2, typename IndexClass2 > - bool operator!= (const CbArray4D< value_type2, IndexClass2 >& rhs) const - { - return !(*this==rhs); - } - /*=======================================================================*/ - reference operator() (const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - - return this->data[indexer.getIndex(x1,x2,x3,x4,nx1,nx2,nx3,nx4)]; - } - /*=======================================================================*/ - const_reference operator() (const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) const - { - #ifdef CbArray4D_RANGECHECKING - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - - return this->data[indexer.getIndex(x1,x2,x3,x4,nx1,nx2,nx3,nx4)]; - } - /*=======================================================================*/ - pointer getStartAdressOfSortedArray(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - - return &this->data[indexer.getStartIndexOfSortedArray(x1,x2,x3,x4,nx1,nx2,nx3,nx4)]; - } - /*=======================================================================*/ - const_pointer getStartAdressOfSortedArray(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - - return &this->data[indexer.getStartIndexOfSortedArray(x1,x2,x3,x4,nx1,nx2,nx3,nx4)]; - } - /*=======================================================================*/ - void setObject(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4, const value_type& value) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - - this->data[indexer.getIndex(x1,x2,x3,x4,nx1,nx2,nx3,nx4)] = value; - } - /*=======================================================================*/ - reference getObject(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - - return this->data[indexer.getIndex(x1,x2,x3,x4,nx1,nx2,nx3,nx4)]; - } - /*=======================================================================*/ - const_reference getObject(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - return (*this)(x1,x2,x3,x4,nx1,nx2,nx3,nx4); - } - /*=======================================================================*/ - bool isEmpty() const { return data.empty(); } - size_type getNX1() const { return this->nx1; } - size_type getNX2() const { return this->nx2; } - size_type getNX3() const { return this->nx3; } - size_type getNX4() const { return this->nx4; } - /*=======================================================================*/ - void reset(const value_type& val) - { - std::fill( this->data.begin(), this->data.end(), val ); - } - /*=======================================================================*/ - std::string toString() const - { - std::stringstream text; - text<<std::setprecision(19); - for(size_type x1=0; x1<this->nx1; x1++) - { - for(size_type x2=0; x2<this->nx2; x2++) - { - for(size_type x3=0; x3<this->nx3; x3++) - { - for(size_type x4=0; x4<this->nx4; x4++) - { - text<<(*this)(x1,x2,x3,x4)<<", "; - } - text<<std::endl; - } - text<<std::endl; - } - text<<std::endl<<std::endl; - } - - return text.str(); - } - /*=======================================================================*/ - std::string getInfo() const - { - std::stringstream text; - text<<"CbArray4D< storageType="<<typeid(T).name()<<", indexer="<<typeid(IndexClass).name()<<" >"; - text<<"( nx1="<<this->nx1<<", nx2="<<this->nx2<<", nx3="<<this->nx3<<", nx4="<<this->nx4<<")"; - return text.str(); - } - /*=======================================================================*/ - void resize(const size_type& uniformDimensionSize) { this->resize(uniformDimensionSize,uniformDimensionSize,uniformDimensionSize); } - /*=======================================================================*/ - void resize(const size_type& nx1, const size_type& nx2, const size_type& nx3, const size_type& nx4) - { - this->nx1 = nx1; - this->nx2 = nx2; - this->nx3 = nx3; - this->nx4 = nx4; - this->data.resize(nx1*nx2*nx3*nx4); - } - /*=======================================================================*/ - void resize(const size_type& nx1, const size_type& nx2, const size_type& nx3, const size_type& nx4, const value_type& val) - { - this->nx1 = nx1; - this->nx2 = nx2; - this->nx3 = nx3; - this->nx4 = nx4; - this->data.resize(nx1*nx2*nx3*nx4,val); - } - /*=======================================================================*/ - std::vector< value_type >& getDataVector() { return this->data; } - /*=======================================================================*/ - const std::vector< value_type >& getDataVector() const { return this->data; } - /*=======================================================================*/ - inline std::size_t getDataVectorIndex(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if( !this->indicesInRange(x1,x2,x3,x4) ) - UB_THROW( UbException(UB_EXARGS,getExceptionErrorString(x1,x2,x3,x4)) ); - #endif - - return indexer.getIndex(x1,x2,x3,x4,nx1,nx2,nx3,nx4); - } + /*=======================================================================*/ + CbArray4D() { this->resize(0, 0, 0, 0); } + /*=======================================================================*/ + CbArray4D(const size_type &nx1, const size_type &nx2, const size_type &nx3, const size_type &nx4) + { + this->resize(nx1, nx2, nx3, nx4); + } + /*=======================================================================*/ + CbArray4D(const size_type &nx1, const size_type &nx2, const size_type &nx3, const size_type &nx4, + const value_type &val) + { + this->resize(nx1, nx2, nx3, nx4, val); + } + /*=======================================================================*/ + CbArray4D(const size_type &uniformDimensionSize /*nx1=nx2=nx3=nx4*/) + { + this->resize(uniformDimensionSize, uniformDimensionSize, uniformDimensionSize, uniformDimensionSize); + } + /*=======================================================================*/ + // ubernimmt vector als daten vector! (erstellt KEINE kopie!!!, vec ist anschliessend leer, da swap verwendet wird) + CbArray4D(std::vector<value_type> &vec, const size_type &nx1, const size_type &nx2, const size_type &nx3, + const size_type &nx4) + { + assert((nx1 * nx2 * nx3 * nx4) == vec.size()); + this->data.swap(vec); + this->resize(nx1, nx2, nx3, nx4); + } + /*=======================================================================*/ + CbArray4D(const CbArray4D &src) : nx1(src.nx1), nx2(src.nx2), nx3(src.nx3), nx4(src.nx4), data(src.data) {} + /*=======================================================================*/ + template <typename value_type2> + CbArray4D(const CbArray4D<value_type2> &src) : nx1(src.nx1), nx2(src.nx2), nx3(src.nx3), nx4(src.nx4) + { + // Sourcedaten kopieren + this->data.resize(src.data.size()); + for (std::size_t i = 0; i < data.size(); ++i) + this->data[i] = src.data[i]; + } + /*=======================================================================*/ + virtual ~CbArray4D() = default; + /*=======================================================================*/ + CbArray4D &operator=(const CbArray4D &rhs) + { + if (this == &rhs) + return *this; + + this->nx1 = rhs.nx1; + this->nx2 = rhs.nx2; + this->nx3 = rhs.nx3; + this->nx4 = rhs.nx4; + + // gespeicherte Datenelemente loeschen + // Laenge anpassen + this->data.resize(rhs.data.size()); + // gespeicherte Datenelemente loeschen + this->data.clear(); + + // Sourcedaten kopieren + this->data = rhs.data; + + return *this; + } + /*=======================================================================*/ + // durch value_type2 kann man z.B. ein float Array einem double Array zuweisen! + template <typename value_type2, typename IndexClass2> + CbArray4D &operator=(const CbArray4D<value_type2, IndexClass2> &rhs) + { + this->nx1 = rhs.nx1; + this->nx2 = rhs.nx2; + this->nx3 = rhs.nx3; + this->nx4 = rhs.nx4; + + // gespeicherte Datenelemente loeschen + this->data.clear(); + // Laenge anpassen + this->data.resize(rhs.data.size()); + + // Sourcedaten kopieren (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) + for (int x1 = 0; x1 < this->nx1; x1++) + for (int x2 = 0; x2 < this->nx2; x2++) + for (int x3 = 0; x3 < this->nx3; x3++) + for (int x4 = 0; x4 < this->nx4; x4++) + this->operator()(x1, x2, x3, x4) = static_cast<value_type>(rhs.operator()(x1, x2, x3, x4)); + + return *this; + } + /*=======================================================================*/ + bool operator==(const CbArray4D &rhs) const + { + if (this == &rhs) + return true; + + if (this->nx1 != rhs.nx1 || this->nx2 != rhs.nx2 || this->nx3 != rhs.nx3 || this->nx4 != rhs.nx4 || + this->data.size() != rhs.data.size()) { + return false; + } + + return std::equal(this->data.begin(), this->data.end(), rhs.data.begin(), UbEqual<value_type, value_type>()); + } + /*=======================================================================*/ + template <typename value_type2, typename IndexClass2> + bool operator==(const CbArray4D<value_type2, IndexClass2> &rhs) const + { + if (this->data.size() != rhs.data.size()) + return false; + + // Sourcedaten einzeln checken (!! koennte anderen Indexer besitzen!!! -> operator() benutzen) + for (int x4 = 0; x4 < this->nx4; x4++) + for (int x3 = 0; x3 < this->nx3; x3++) + for (int x2 = 0; x2 < this->nx2; x2++) + for (int x1 = 0; x1 < this->nx1; x1++) + if (!isUbEqual(this->operator()(x1, x2, x3, x4), rhs.operator()(x1, x2, x3, x4))) + return false; + + return true; + } + /*=======================================================================*/ + bool operator!=(const CbArray4D &rhs) const { return !(*this == rhs); } + /*=======================================================================*/ + template <typename value_type2, typename IndexClass2> + bool operator!=(const CbArray4D<value_type2, IndexClass2> &rhs) const + { + return !(*this == rhs); + } + /*=======================================================================*/ + reference operator()(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + + return this->data[indexer.getIndex(x1, x2, x3, x4, nx1, nx2, nx3, nx4)]; + } + /*=======================================================================*/ + const_reference operator()(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4) const + { +#ifdef CbArray4D_RANGECHECKING + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + + return this->data[indexer.getIndex(x1, x2, x3, x4, nx1, nx2, nx3, nx4)]; + } + /*=======================================================================*/ + pointer getStartAdressOfSortedArray(const size_type &x1, const size_type &x2, const size_type &x3, + const size_type &x4) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + + return &this->data[indexer.getStartIndexOfSortedArray(x1, x2, x3, x4, nx1, nx2, nx3, nx4)]; + } + /*=======================================================================*/ + const_pointer getStartAdressOfSortedArray(const size_type &x1, const size_type &x2, const size_type &x3, + const size_type &x4) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + + return &this->data[indexer.getStartIndexOfSortedArray(x1, x2, x3, x4, nx1, nx2, nx3, nx4)]; + } + /*=======================================================================*/ + void setObject(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4, + const value_type &value) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + + this->data[indexer.getIndex(x1, x2, x3, x4, nx1, nx2, nx3, nx4)] = value; + } + /*=======================================================================*/ + reference getObject(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + + return this->data[indexer.getIndex(x1, x2, x3, x4, nx1, nx2, nx3, nx4)]; + } + /*=======================================================================*/ + const_reference getObject(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + return (*this)(x1, x2, x3, x4, nx1, nx2, nx3, nx4); + } + /*=======================================================================*/ + bool isEmpty() const { return data.empty(); } + size_type getNX1() const { return this->nx1; } + size_type getNX2() const { return this->nx2; } + size_type getNX3() const { return this->nx3; } + size_type getNX4() const { return this->nx4; } + /*=======================================================================*/ + void reset(const value_type &val) { std::fill(this->data.begin(), this->data.end(), val); } + /*=======================================================================*/ + std::string toString() const + { + std::stringstream text; + text << std::setprecision(19); + for (size_type x1 = 0; x1 < this->nx1; x1++) { + for (size_type x2 = 0; x2 < this->nx2; x2++) { + for (size_type x3 = 0; x3 < this->nx3; x3++) { + for (size_type x4 = 0; x4 < this->nx4; x4++) { + text << (*this)(x1, x2, x3, x4) << ", "; + } + text << std::endl; + } + text << std::endl; + } + text << std::endl << std::endl; + } + + return text.str(); + } + /*=======================================================================*/ + std::string getInfo() const + { + std::stringstream text; + text << "CbArray4D< storageType=" << typeid(T).name() << ", indexer=" << typeid(IndexClass).name() << " >"; + text << "( nx1=" << this->nx1 << ", nx2=" << this->nx2 << ", nx3=" << this->nx3 << ", nx4=" << this->nx4 << ")"; + return text.str(); + } + /*=======================================================================*/ + void resize(const size_type &uniformDimensionSize) + { + this->resize(uniformDimensionSize, uniformDimensionSize, uniformDimensionSize); + } + /*=======================================================================*/ + void resize(const size_type &nx1, const size_type &nx2, const size_type &nx3, const size_type &nx4) + { + this->nx1 = nx1; + this->nx2 = nx2; + this->nx3 = nx3; + this->nx4 = nx4; + this->data.resize(nx1 * nx2 * nx3 * nx4); + } + /*=======================================================================*/ + void resize(const size_type &nx1, const size_type &nx2, const size_type &nx3, const size_type &nx4, + const value_type &val) + { + this->nx1 = nx1; + this->nx2 = nx2; + this->nx3 = nx3; + this->nx4 = nx4; + this->data.resize(nx1 * nx2 * nx3 * nx4, val); + } + /*=======================================================================*/ + std::vector<value_type> &getDataVector() { return this->data; } + /*=======================================================================*/ + const std::vector<value_type> &getDataVector() const { return this->data; } + /*=======================================================================*/ + inline std::size_t getDataVectorIndex(const size_type &x1, const size_type &x2, const size_type &x3, + const size_type &x4) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (!this->indicesInRange(x1, x2, x3, x4)) + UB_THROW(UbException(UB_EXARGS, getExceptionErrorString(x1, x2, x3, x4))); +#endif + + return indexer.getIndex(x1, x2, x3, x4, nx1, nx2, nx3, nx4); + } protected: - /*=======================================================================*/ - //success -> true - //else -> false - inline bool indicesInRange(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) const - { - if( x1 < 0 || x1 >= this->nx1 - || x2 < 0 || x2 >= this->nx2 - || x3 < 0 || x3 >= this->nx3 - || x4 < 0 || x4 >= this->nx4 ) - { - return false; - } - return true; - } - /*=======================================================================*/ - std::string getExceptionErrorString(const size_type& x1, const size_type& x2, const size_type& x3, const size_type& x4) const - { - std::stringstream out("index out of range - "); - out<<"("<<x1<<","<<x2<<","<<x3<<","<<x4<<") not in ("<<nx1<<","<<nx2<<","<<nx3<<","<<nx4<<")"; - return out.str(); - } - /*=======================================================================*/ + /*=======================================================================*/ + // success -> true + // else -> false + inline bool indicesInRange(const size_type &x1, const size_type &x2, const size_type &x3, const size_type &x4) const + { + if (x1 < 0 || x1 >= this->nx1 || x2 < 0 || x2 >= this->nx2 || x3 < 0 || x3 >= this->nx3 || x4 < 0 || + x4 >= this->nx4) { + return false; + } + return true; + } + /*=======================================================================*/ + std::string getExceptionErrorString(const size_type &x1, const size_type &x2, const size_type &x3, + const size_type &x4) const + { + std::stringstream out("index out of range - "); + out << "(" << x1 << "," << x2 << "," << x3 << "," << x4 << ") not in (" << nx1 << "," << nx2 << "," << nx3 + << "," << nx4 << ")"; + return out.str(); + } + /*=======================================================================*/ protected: - size_type nx1; - size_type nx2; - size_type nx3; - size_type nx4; - indexer_type indexer; - std::vector< value_type > data; - + size_type nx1; + size_type nx2; + size_type nx3; + size_type nx4; + indexer_type indexer; + std::vector<value_type> data; }; -#endif //CBARRAY4D_H +#endif // CBARRAY4D_H diff --git a/src/basics/basics/container/CbVector.h b/src/basics/basics/container/CbVector.h index 49ccfcfac..3cf88151e 100644 --- a/src/basics/basics/container/CbVector.h +++ b/src/basics/basics/container/CbVector.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,22 +33,24 @@ #ifndef CBVECTOR_H #define CBVECTOR_H +#include <PointerDefinitions.h> //for memcopy +#include <algorithm> //for std::swap +#include <typeinfo> //for typeid #include <vector> -#include <algorithm> //for std::swap -#include <typeinfo> //for typeid -#include <PointerDefinitions.h> //for memcopy -#include <basics/utilities/UbSystem.h> #include <basics/utilities/UbEqual.h> +#include <basics/utilities/UbSystem.h> -template< typename T > class CbVectorAllocator; -template< typename T > class CbVectorAllocatorStd; +template <typename T> +class CbVectorAllocator; +template <typename T> +class CbVectorAllocatorStd; //========================================================================= //! \brief A class implements a container like a vector //! \details //! For this class it was required to ave only the type as template argument. -//! Hence, the allocator must be an abstract class. With out this requirement, +//! Hence, the allocator must be an abstract class. With out this requirement, //! an allocator as second template argument would have been possible, as in the //! STL vector. This would lead to the compiler generating two different classes //! for the same data type with different allocators during compile time. Here it @@ -59,250 +61,250 @@ template< typename T > class CbVectorAllocatorStd; //! -release: not defined "NO_CB_RANGECHECK" && defined "CB_RANGECHECK" //========================================================================= ////////////////////////////////////////////////////////////////////////// -template< typename T > +template <typename T> class CbVector { public: - using value_type = T; - using pointer = value_type *; - using size_type = std::size_t; + using value_type = T; + using pointer = value_type *; + using size_type = std::size_t; - friend class CbVectorAllocator<value_type>; //um auf ptrData und dataSize zugreifen zu koennen! + friend class CbVectorAllocator<value_type>; // um auf ptrData und dataSize zugreifen zu koennen! + + CbVector<value_type>(const CbVector<value_type> &src) = delete; - CbVector<value_type>(const CbVector<value_type>& src) = delete; public: - /*==========================================================*/ - CbVector( CbVectorAllocator<value_type>* const& allocator = new CbVectorAllocatorStd<value_type> ) - : ptrData(NULL) - , - allocator(allocator) - { - this->allocator->alloc(*this,0,value_type()); - } - /*==========================================================*/ - CbVector( const size_type size, CbVectorAllocator<value_type>* const& allocator = new CbVectorAllocatorStd<value_type>, const value_type& value=value_type() ) - : ptrData(NULL) - , - allocator(allocator) - { - this->allocator->alloc(*this,size,value); - } - /*==========================================================*/ - virtual ~CbVector() - { - if(allocator) - { - this->allocator->dealloc(*this); - delete allocator; - allocator=NULL; - } - } - /*=======================================================================*/ - CbVector& operator= (const CbVector& src) - { - if(this == &src) - return *this; + /*==========================================================*/ + CbVector(CbVectorAllocator<value_type> *const &allocator = new CbVectorAllocatorStd<value_type>) + : ptrData(NULL), allocator(allocator) + { + this->allocator->alloc(*this, 0, value_type()); + } + /*==========================================================*/ + CbVector(const size_type size, + CbVectorAllocator<value_type> *const &allocator = new CbVectorAllocatorStd<value_type>, + const value_type &value = value_type()) + : ptrData(NULL), allocator(allocator) + { + this->allocator->alloc(*this, size, value); + } + /*==========================================================*/ + virtual ~CbVector() + { + if (allocator) { + this->allocator->dealloc(*this); + delete allocator; + allocator = NULL; + } + } + /*=======================================================================*/ + CbVector &operator=(const CbVector &src) + { + if (this == &src) + return *this; - //gespeicherte Datenelemente loeschen - //Laenge anpassen - this->allocator->resize(*this, src.size()); + // gespeicherte Datenelemente loeschen + // Laenge anpassen + this->allocator->resize(*this, src.size()); - //gespeicherte Datenelemente kopieren - if( !src.empty() ) - { - memcpy( (char*)ptrData, (char*)&src[0], src.size()*sizeof(value_type) ); - //for(size_type i=0; i<src.size(); i++) - // (*this)[i] = src[i]; - } + // gespeicherte Datenelemente kopieren + if (!src.empty()) { + memcpy((char *)ptrData, (char *)&src[0], src.size() * sizeof(value_type)); + // for(size_type i=0; i<src.size(); i++) + // (*this)[i] = src[i]; + } - return *this; - } - /*=======================================================================*/ - CbVector& operator= (const std::vector< value_type >& src) - { - //gespeicherte Datenelemente loeschen - //Laenge anpassen - this->allocator->resize(*this, src.size()); + return *this; + } + /*=======================================================================*/ + CbVector &operator=(const std::vector<value_type> &src) + { + // gespeicherte Datenelemente loeschen + // Laenge anpassen + this->allocator->resize(*this, src.size()); - //gespeicherte Datenelemente kopieren - if( !src.empty() ) - { - memcpy( (char*)ptrData, (char*)&src[0], src.size()*sizeof(value_type) ); - //for(size_type i=0; i<src.size(); i++) - // (*this)[i] = src[i]; - } - - return *this; - } - /*=======================================================================*/ - bool operator== (const CbVector& rhs) const - { - if( this == &rhs ) return true; - if( this->dataSize != rhs.dataSize ) return false; + // gespeicherte Datenelemente kopieren + if (!src.empty()) { + memcpy((char *)ptrData, (char *)&src[0], src.size() * sizeof(value_type)); + // for(size_type i=0; i<src.size(); i++) + // (*this)[i] = src[i]; + } - for(size_type i=0; i<rhs.size(); i++) - if( !isUbEqual( this->operator[](i), rhs.operator[](i) ) ) + return *this; + } + /*=======================================================================*/ + bool operator==(const CbVector &rhs) const + { + if (this == &rhs) + return true; + if (this->dataSize != rhs.dataSize) return false; - return true; - } - /*==========================================================*/ - void setAllocator( CbVectorAllocator<value_type>* const& allocator ) - { - if(this->allocator) - { - if(this->allocator==allocator) return; - this->allocator->dealloc(*this); - delete this->allocator; - } - this->allocator = allocator; - this->allocator->alloc(*this,0); - } - /*==========================================================*/ - size_type size() const { return dataSize; } - /*==========================================================*/ - bool empty() const { return dataSize==0; } - /*==========================================================*/ - bool resize(const size_type& dataSize) - { - return allocator->resize(*this, dataSize); - } - /*==========================================================*/ - bool resize(const size_type& dataSize, const value_type& value) - { - return allocator->resize(*this, dataSize, value); - } - /*==========================================================*/ - void swap(CbVector& rhs) - { - if( this == &rhs ) return; + for (size_type i = 0; i < rhs.size(); i++) + if (!isUbEqual(this->operator[](i), rhs.operator[](i))) + return false; + + return true; + } + /*==========================================================*/ + void setAllocator(CbVectorAllocator<value_type> *const &allocator) + { + if (this->allocator) { + if (this->allocator == allocator) + return; + this->allocator->dealloc(*this); + delete this->allocator; + } + this->allocator = allocator; + this->allocator->alloc(*this, 0); + } + /*==========================================================*/ + size_type size() const { return dataSize; } + /*==========================================================*/ + bool empty() const { return dataSize == 0; } + /*==========================================================*/ + bool resize(const size_type &dataSize) { return allocator->resize(*this, dataSize); } + /*==========================================================*/ + bool resize(const size_type &dataSize, const value_type &value) + { + return allocator->resize(*this, dataSize, value); + } + /*==========================================================*/ + void swap(CbVector &rhs) + { + if (this == &rhs) + return; - std::swap( this->ptrData , rhs.ptrData ); - std::swap( this->dataSize , rhs.dataSize ); - std::swap( this->allocator, rhs.allocator ); - } - /*==========================================================*/ - value_type& operator[](const size_type& i) - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if(i>=dataSize) - UB_THROW( UbException(UB_EXARGS,"T="+(std::string)typeid(*this).name()+UbSystem::toString(i)+" out of range (size="+UbSystem::toString(dataSize)+")") ); - #endif // _DEBUG + std::swap(this->ptrData, rhs.ptrData); + std::swap(this->dataSize, rhs.dataSize); + std::swap(this->allocator, rhs.allocator); + } + /*==========================================================*/ + value_type &operator[](const size_type &i) + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (i >= dataSize) + UB_THROW(UbException(UB_EXARGS, "T=" + (std::string) typeid(*this).name() + UbSystem::toString(i) + + " out of range (size=" + UbSystem::toString(dataSize) + ")")); +#endif // _DEBUG - return ptrData[i]; - } - /*==========================================================*/ - const value_type& operator[](const size_type& i) const - { - #if !defined(NO_CB_RANGECHECK) && ( defined(_DEBUG) || defined(CB_RANGECHECK) ) - if(i>=dataSize) - UB_THROW( UbException(UB_EXARGS,"T="+(std::string)typeid(*this).name()+UbSystem::toString(i)+" out of range (size="+UbSystem::toString(dataSize)+")") ); - #endif // _DEBUG + return ptrData[i]; + } + /*==========================================================*/ + const value_type &operator[](const size_type &i) const + { +#if !defined(NO_CB_RANGECHECK) && (defined(_DEBUG) || defined(CB_RANGECHECK)) + if (i >= dataSize) + UB_THROW(UbException(UB_EXARGS, "T=" + (std::string) typeid(*this).name() + UbSystem::toString(i) + + " out of range (size=" + UbSystem::toString(dataSize) + ")")); +#endif // _DEBUG - return ptrData[i]; - } - /*==========================================================*/ - CbVectorAllocator<value_type>* getAllocator() const { return allocator; } - /*==========================================================*/ + return ptrData[i]; + } + /*==========================================================*/ + CbVectorAllocator<value_type> *getAllocator() const { return allocator; } + /*==========================================================*/ private: - value_type* ptrData; - size_type dataSize{0}; - CbVectorAllocator<value_type>* allocator; - //CbVector<value_type>& operator=(const CbVector<value_type>& src); + value_type *ptrData; + size_type dataSize{ 0 }; + CbVectorAllocator<value_type> *allocator; + // CbVector<value_type>& operator=(const CbVector<value_type>& src); }; ////////////////////////////////////////////////////////////////////////// // CbVectorAllocator-Interface ////////////////////////////////////////////////////////////////////////// -template< typename T > +template <typename T> class CbVectorAllocator { public: - using value_type = typename CbVector<T>::value_type; - using size_type = typename CbVector<value_type>::size_type; + using value_type = typename CbVector<T>::value_type; + using size_type = typename CbVector<value_type>::size_type; public: - CbVectorAllocator() = default; - virtual ~CbVectorAllocator() = default; + CbVectorAllocator() = default; + virtual ~CbVectorAllocator() = default; - virtual bool alloc(CbVector< value_type >& vec, const size_type& dataSize, const value_type& value=value_type()) = 0; - virtual bool resize(CbVector< value_type >& vec, const size_type& dataSize, const value_type& value=value_type()) = 0; - virtual bool dealloc(CbVector< value_type >& vec) = 0; + virtual bool alloc(CbVector<value_type> &vec, const size_type &dataSize, + const value_type &value = value_type()) = 0; + virtual bool resize(CbVector<value_type> &vec, const size_type &dataSize, + const value_type &value = value_type()) = 0; + virtual bool dealloc(CbVector<value_type> &vec) = 0; protected: - //folgende Methoden ersparen eine friend Deklaierung aller moeglichen Allocatoren - //denn durch diese beiden Methoden haben sie exklusive Zugriffsrechte! - //**********************************************************************************// - inline value_type*& ptrDataOf( CbVector< value_type >& vec ) - { - if( vec.getAllocator()!=this ) UB_THROW( UbException(UB_EXARGS,"allocator is not member of vec!") ); - return vec.ptrData; - } - //**********************************************************************************// - inline size_type& dataSizeOf( CbVector< value_type >& vec ) - { - if( vec.getAllocator()!=this ) UB_THROW( UbException(UB_EXARGS,"allocator is not member of vec!") ); - return vec.dataSize; - } + // folgende Methoden ersparen eine friend Deklaierung aller moeglichen Allocatoren + // denn durch diese beiden Methoden haben sie exklusive Zugriffsrechte! + //**********************************************************************************// + inline value_type *&ptrDataOf(CbVector<value_type> &vec) + { + if (vec.getAllocator() != this) + UB_THROW(UbException(UB_EXARGS, "allocator is not member of vec!")); + return vec.ptrData; + } + //**********************************************************************************// + inline size_type &dataSizeOf(CbVector<value_type> &vec) + { + if (vec.getAllocator() != this) + UB_THROW(UbException(UB_EXARGS, "allocator is not member of vec!")); + return vec.dataSize; + } }; ////////////////////////////////////////////////////////////////////////// // CbVectorAllocatorStd ////////////////////////////////////////////////////////////////////////// -template< typename T > +template <typename T> class CbVectorAllocatorStd : public CbVectorAllocator<T> { public: - //typedefs wiederholen, da Basisklasse = template -> "Dependent-Base"-Problem - using value_type = typename CbVector<T>::value_type; - using size_type = typename CbVector<value_type>::size_type; + // typedefs wiederholen, da Basisklasse = template -> "Dependent-Base"-Problem + using value_type = typename CbVector<T>::value_type; + using size_type = typename CbVector<value_type>::size_type; public: - CbVectorAllocatorStd() : CbVectorAllocator<value_type>() - { - - } - /*==========================================================*/ - bool alloc(CbVector< value_type >& src, const size_type& dataSize, const value_type& value=value_type()) override - { - return this->resize(src,dataSize,value); - } - /*==========================================================*/ - bool resize(CbVector< value_type >& vec, const size_type& dataSize, const value_type& value=value_type()) override - { - if( CbVectorAllocatorStd< value_type >::dataSizeOf(vec) == dataSize) return false; + CbVectorAllocatorStd() : CbVectorAllocator<value_type>() {} + /*==========================================================*/ + bool alloc(CbVector<value_type> &src, const size_type &dataSize, const value_type &value = value_type()) override + { + return this->resize(src, dataSize, value); + } + /*==========================================================*/ + bool resize(CbVector<value_type> &vec, const size_type &dataSize, const value_type &value = value_type()) override + { + if (CbVectorAllocatorStd<value_type>::dataSizeOf(vec) == dataSize) + return false; - //new array - value_type* new_data = new value_type[dataSize]; - //copy existing data to array - if( this->ptrDataOf(vec) ) - { - for(size_type i=0; (i<vec.size() && i<dataSize); ++i) new_data[i] = CbVectorAllocatorStd< value_type >::ptrDataOf(vec)[i]; - delete[] this->ptrDataOf(vec); - } - this->ptrDataOf(vec) = new_data; - //new value for new items - for(size_type i=this->dataSizeOf(vec); i<dataSize; ++i) this->ptrDataOf(vec)[i] = value; - //assign new dataSize - this->dataSizeOf(vec) = dataSize; + // new array + value_type *new_data = new value_type[dataSize]; + // copy existing data to array + if (this->ptrDataOf(vec)) { + for (size_type i = 0; (i < vec.size() && i < dataSize); ++i) + new_data[i] = CbVectorAllocatorStd<value_type>::ptrDataOf(vec)[i]; + delete[] this->ptrDataOf(vec); + } + this->ptrDataOf(vec) = new_data; + // new value for new items + for (size_type i = this->dataSizeOf(vec); i < dataSize; ++i) + this->ptrDataOf(vec)[i] = value; + // assign new dataSize + this->dataSizeOf(vec) = dataSize; - return true; - } - /*==========================================================*/ - bool dealloc(CbVector< value_type >& vec) override - { - if( this->ptrDataOf(vec) ) - { - delete[] this->ptrDataOf(vec); - this->ptrDataOf(vec) = NULL; - } - this->dataSizeOf(vec) = 0; - return true; - } - /*==========================================================*/ + return true; + } + /*==========================================================*/ + bool dealloc(CbVector<value_type> &vec) override + { + if (this->ptrDataOf(vec)) { + delete[] this->ptrDataOf(vec); + this->ptrDataOf(vec) = NULL; + } + this->dataSizeOf(vec) = 0; + return true; + } + /*==========================================================*/ private: }; -#endif //CBVECTOR_H +#endif // CBVECTOR_H diff --git a/src/basics/basics/objects/ObObject.h b/src/basics/basics/objects/ObObject.h index 0b543dc18..6d40d8af4 100644 --- a/src/basics/basics/objects/ObObject.h +++ b/src/basics/basics/objects/ObObject.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -41,21 +41,19 @@ class ObObject : public UbObservable { public: ObObject() = default; - ObObject(const std::string& name) : name(name) { } + ObObject(const std::string &name) : name(name) {} - ~ObObject() override = default; + ~ObObject() override = default; - virtual ObObject* clone() = 0; + virtual ObObject *clone() = 0; - virtual std::string getName() { return name; } - void setName(std::string name) { this->name = name; } - - std::string toString() override = 0; + virtual std::string getName() { return name; } + void setName(std::string name) { this->name = name; } + std::string toString() override = 0; private: - std::string name; + std::string name; }; - #endif diff --git a/src/basics/basics/utilities/UbComparators.h b/src/basics/basics/utilities/UbComparators.h index 0e7d2cbed..bc507e456 100644 --- a/src/basics/basics/utilities/UbComparators.h +++ b/src/basics/basics/utilities/UbComparators.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,202 +30,200 @@ //! \ingroup utilities //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#ifndef UBCOMPARATORS_H +#ifndef UBCOMPARATORS_H #define UBCOMPARATORS_H -#include <functional> +#include <functional> namespace UbComparators { - //type_traits - template <typename T> struct MemberInfo; //not defined for correct compiler errors! - - // specialization for MemberFunctionsPtr - // C - class with return T method - template <typename T, typename C> - struct MemberInfo<T C::*> - { - using type = T; - using class_type = C; - - static T& apply( C& c, T C::* ptr ) { return c.*ptr; } - static const T& apply( const C& c, T C::* ptr ) { return c.*ptr; } - }; - //specialization for MemberFunctionsPtr - //C - class with return T method - template <typename T, typename C> - struct MemberInfo<T (C::*)()> - { - using type = T; - using class_type = C; - - static T apply( C& c, T (C::*ptr)() ) { return (c.*ptr)(); } - }; - //specialization for const MemberFunctionsPtr - //C - class with return T method - template <typename T, typename C> - struct MemberInfo<T (C::*)() const> - { - using type = T; - using class_type = C; - - static T apply( const C& c, T (C::*ptr)() const ) { return (c.*ptr)(); } - }; - - //MemberComparative-Class - template <typename Ptr, typename Comp = std::less<typename MemberInfo<Ptr>::type> > - class MemComp - : private Comp // -> usage of Empty Base Class Optimization (EBCO) - { - using C = typename MemberInfo<Ptr>::class_type; - - public: - MemComp( Ptr ptr, Comp c = Comp() ) - : Comp(c), mp_(ptr) - {} - - bool operator()(C& lhs, C& rhs) - { - return Comp::operator()( MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_) ); - } - bool operator()(C& lhs, C& rhs) const - { - return Comp::operator()( MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_) ); - } - bool operator()(const C& lhs, const C& rhs) - { - return Comp::operator()( MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_) ); - } - bool operator()(const C& lhs, const C& rhs) const - { - return Comp::operator()( MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_) ); - } - - private: - Ptr mp_; - }; - - // Factoryfunktionen - template <typename Ptr> - MemComp<Ptr> membercomp(Ptr p) - { - return MemComp<Ptr>(p); - } - - template<typename Comp, typename Ptr> - MemComp<Ptr, Comp> membercomp(Ptr p, Comp c = Comp()) - { - return MemComp<Ptr, Comp>(p, c); - } - - template<template<typename> class Comp, typename Ptr> - MemComp<Ptr, Comp<typename MemberInfo<Ptr>::type> > - membercomp(Ptr p, Comp<typename MemberInfo<Ptr>::type> c = Comp<typename MemberInfo<Ptr>::type>()) - { - return MemComp<Ptr, Comp<typename MemberInfo<Ptr>::type> >(p, c); - } - - - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - //andere Variante (alerdings ist hier keine Deduction moeglich!!!) - ////////////////////////////////////////////////////////////////////////// - //Vergleichs-Templates: - //Funktor zum "non-const" Methodenvergleich: liste.sort( compareMethods<Klasse, int, &Klasse::getVal1 ); - template<typename K/*Klasse*/, typename M /*MethodenRueckgabeTyp*/, M (K::*fct)() /*MethodenPointer*/> // Allgemeiner Fall - struct compareMethods - { - bool operator()(K& r, K& l) const // da fct nicht const ist, kann auch K nicht const sein. das const hinter der deklaration besagt dass compareMethods const sein kann - { return (r.*fct)() < (l.*fct)(); } - }; - ////////////////////////////////////////////////////////////////////////// - //Funktor zum "const" Methodenvergleich: liste.sort( compareMethods<Klasse, int, &Klasse::getVal1 ); - template<typename K/*Klasse*/, typename M /*MethodenRueckgabeTyp*/, M (K::*fct)() const /*MethodenPointer*/> // <- hier const - struct compareConstMethods - { - bool operator()(const K& r, const K& l) const //hier koennen die K's auch const sein, muessen sie aber nicht (const hinzufuegen geht ja problemlos) - { return (r.*fct)() < (l.*fct)(); } - }; - ////////////////////////////////////////////////////////////////////////// - //Funktor zum Membervergleich: lise.sort( compareMember<Klasse, int, &Klasse::member>() ); - template<typename K/*Klasse*/, typename M /*MemberTyp*/, M (K::*Member) /*MemberPointer*/> // <- hier const - struct compareMember - { - bool operator()(const K& r,const K& l) const - { return r.*Member < l.*Member; } - }; - //Bsp: - //class Klasse{ - //public: - // Klasse(double val1, double val2 ) : val1(val1),val2(val2) {} - // double getVal1() { return val1; } - // double getVal2() const { return val2; } // <- hier const - // double val1, val2; - //}; - //int main(int argc, char** argv){ - // std::list<Klasse> l; - // l.push_back( Klasse(10,10) ); - // l.push_back( Klasse(1,5) ); - // l.sort( compareMember<Klasse, double, &Klasse::val1 >() ); - // l.sort( compareMethods<Klasse, double, &Klasse::getVal1 >() ); - // l.sort( compareConstMethods<Klasse, double, &Klasse::getVal1 >() ); - //} +// type_traits +template <typename T> +struct MemberInfo; // not defined for correct compiler errors! + +// specialization for MemberFunctionsPtr +// C - class with return T method +template <typename T, typename C> +struct MemberInfo<T C::*> { + using type = T; + using class_type = C; + + static T &apply(C &c, T C::*ptr) { return c.*ptr; } + static const T &apply(const C &c, T C::*ptr) { return c.*ptr; } +}; +// specialization for MemberFunctionsPtr +// C - class with return T method +template <typename T, typename C> +struct MemberInfo<T (C::*)()> { + using type = T; + using class_type = C; + + static T apply(C &c, T (C::*ptr)()) { return (c.*ptr)(); } +}; +// specialization for const MemberFunctionsPtr +// C - class with return T method +template <typename T, typename C> +struct MemberInfo<T (C::*)() const> { + using type = T; + using class_type = C; + + static T apply(const C &c, T (C::*ptr)() const) { return (c.*ptr)(); } +}; +// MemberComparative-Class +template <typename Ptr, typename Comp = std::less<typename MemberInfo<Ptr>::type>> +class MemComp : private Comp // -> usage of Empty Base Class Optimization (EBCO) +{ + using C = typename MemberInfo<Ptr>::class_type; + +public: + MemComp(Ptr ptr, Comp c = Comp()) : Comp(c), mp_(ptr) {} + + bool operator()(C &lhs, C &rhs) + { + return Comp::operator()(MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_)); + } + bool operator()(C &lhs, C &rhs) const + { + return Comp::operator()(MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_)); + } + bool operator()(const C &lhs, const C &rhs) + { + return Comp::operator()(MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_)); + } + bool operator()(const C &lhs, const C &rhs) const + { + return Comp::operator()(MemberInfo<Ptr>::apply(lhs, mp_), MemberInfo<Ptr>::apply(rhs, mp_)); + } + +private: + Ptr mp_; }; -#endif //UBCOMPARATOR_H - -//example -// #include <basics/utilities/UbComparators.h" -// #include <list> -// using namespace std; -// using namespace UbComparators; -// -// struct S { -// S(int i) :x(i) {} -// int x; -// float f() {return x;}; -// double g() const {return x;} -// }; -// -// struct intComp { -// bool operator()(int l, int r) const -// { return l > r; } -// }; -// -// struct dblComp { -// bool operator()(double l, double r) const -// { return l > r; } -// }; -// -// template <typename T> -// struct genComp { +// Factoryfunktionen +template <typename Ptr> +MemComp<Ptr> membercomp(Ptr p) +{ + return MemComp<Ptr>(p); +} + +template <typename Comp, typename Ptr> +MemComp<Ptr, Comp> membercomp(Ptr p, Comp c = Comp()) +{ + return MemComp<Ptr, Comp>(p, c); +} + +template <template <typename> class Comp, typename Ptr> +MemComp<Ptr, Comp<typename MemberInfo<Ptr>::type>> +membercomp(Ptr p, Comp<typename MemberInfo<Ptr>::type> c = Comp<typename MemberInfo<Ptr>::type>()) +{ + return MemComp<Ptr, Comp<typename MemberInfo<Ptr>::type>>(p, c); +} + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// +// andere Variante (alerdings ist hier keine Deduction moeglich!!!) +////////////////////////////////////////////////////////////////////////// +// Vergleichs-Templates: +// Funktor zum "non-const" Methodenvergleich: liste.sort( compareMethods<Klasse, int, &Klasse::getVal1 ); +template <typename K /*Klasse*/, typename M /*MethodenRueckgabeTyp*/, + M (K::*fct)() /*MethodenPointer*/> // Allgemeiner Fall +struct compareMethods { + bool operator()(K &r, K &l) const // da fct nicht const ist, kann auch K nicht const sein. das const hinter der + // deklaration besagt dass compareMethods const sein kann + { + return (r.*fct)() < (l.*fct)(); + } +}; +////////////////////////////////////////////////////////////////////////// +// Funktor zum "const" Methodenvergleich: liste.sort( compareMethods<Klasse, int, &Klasse::getVal1 ); +template <typename K /*Klasse*/, typename M /*MethodenRueckgabeTyp*/, + M (K::*fct)() const /*MethodenPointer*/> // <- hier const +struct compareConstMethods { + bool operator()(const K &r, const K &l) + const // hier koennen die K's auch const sein, muessen sie aber nicht (const hinzufuegen geht ja problemlos) + { + return (r.*fct)() < (l.*fct)(); + } +}; +////////////////////////////////////////////////////////////////////////// +// Funktor zum Membervergleich: lise.sort( compareMember<Klasse, int, &Klasse::member>() ); +template <typename K /*Klasse*/, typename M /*MemberTyp*/, M(K::*Member) /*MemberPointer*/> // <- hier const +struct compareMember { + bool operator()(const K &r, const K &l) const { return r.*Member < l.*Member; } +}; +// Bsp: +// class Klasse{ +// public: +// Klasse(double val1, double val2 ) : val1(val1),val2(val2) {} +// double getVal1() { return val1; } +// double getVal2() const { return val2; } // <- hier const +// double val1, val2; +//}; +// int main(int argc, char** argv){ +// std::list<Klasse> l; +// l.push_back( Klasse(10,10) ); +// l.push_back( Klasse(1,5) ); +// l.sort( compareMember<Klasse, double, &Klasse::val1 >() ); +// l.sort( compareMethods<Klasse, double, &Klasse::getVal1 >() ); +// l.sort( compareConstMethods<Klasse, double, &Klasse::getVal1 >() ); +//} + +}; // namespace UbComparators + +#endif // UBCOMPARATOR_H + +// example +// #include <basics/utilities/UbComparators.h" +// #include <list> +// using namespace std; +// using namespace UbComparators; +// +// struct S { +// S(int i) :x(i) {} +// int x; +// float f() {return x;}; +// double g() const {return x;} +// }; +// +// struct intComp { +// bool operator()(int l, int r) const +// { return l > r; } +// }; +// +// struct dblComp { +// bool operator()(double l, double r) const +// { return l > r; } +// }; +// +// template <typename T> +// struct genComp { // bool operator()(const T& l, const T& r) const -// { return l > r; } -// }; -// -// -// int main() -// { -// S a(1); -// S b(2); -// list<S> sList; -// sList.push_back(a); -// sList.push_back(b); -// sList.sort(UbComparators::membercomp(&S::x,intComp())); //calls overload (1) -// sList.sort(UbComparators::membercomp<intComp>(&S::x)); //same -// sList.sort(UbComparators::membercomp(&S::x)); //calls overload (5) -// sList.sort(UbComparators::membercomp<genComp>(&S::x)); //calls overload(3) -// sList.sort(UbComparators::membercomp(&S::x, genComp<int>())); //calls overload(1) -// //same for nonconst function -// sList.sort(UbComparators::membercomp(&S::f, dblComp())); //overload(2) -// sList.sort(UbComparators::membercomp<dblComp>(&S::f)); //same -// sList.sort(UbComparators::membercomp(&S::f)); //overload(6) -// sList.sort(UbComparators::membercomp<genComp>(&S::f)); //overload(4) -// //same for const function -// sList.sort(UbComparators::membercomp(&S::g, dblComp())); //overload(2) -// sList.sort(UbComparators::membercomp<dblComp>(&S::g)); //same -// sList.sort(UbComparators::membercomp(&S::g)); //overload(6) -// sList.sort(UbComparators::membercomp<genComp>(&S::g)); //overload(4) -// } +// { return l > r; } +// }; +// +// +// int main() +// { +// S a(1); +// S b(2); +// list<S> sList; +// sList.push_back(a); +// sList.push_back(b); +// sList.sort(UbComparators::membercomp(&S::x,intComp())); //calls overload (1) +// sList.sort(UbComparators::membercomp<intComp>(&S::x)); //same +// sList.sort(UbComparators::membercomp(&S::x)); //calls overload (5) +// sList.sort(UbComparators::membercomp<genComp>(&S::x)); //calls overload(3) +// sList.sort(UbComparators::membercomp(&S::x, genComp<int>())); //calls overload(1) +// //same for nonconst function +// sList.sort(UbComparators::membercomp(&S::f, dblComp())); //overload(2) +// sList.sort(UbComparators::membercomp<dblComp>(&S::f)); //same +// sList.sort(UbComparators::membercomp(&S::f)); //overload(6) +// sList.sort(UbComparators::membercomp<genComp>(&S::f)); //overload(4) +// //same for const function +// sList.sort(UbComparators::membercomp(&S::g, dblComp())); //overload(2) +// sList.sort(UbComparators::membercomp<dblComp>(&S::g)); //same +// sList.sort(UbComparators::membercomp(&S::g)); //overload(6) +// sList.sort(UbComparators::membercomp<genComp>(&S::g)); //overload(4) +// } diff --git a/src/basics/basics/utilities/UbEqual.h b/src/basics/basics/utilities/UbEqual.h index c605c36ef..b3ca9102d 100644 --- a/src/basics/basics/utilities/UbEqual.h +++ b/src/basics/basics/utilities/UbEqual.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,7 +33,7 @@ #ifndef UBEQUAL_H #define UBEQUAL_H -#include<cmath> +#include <cmath> ////////////////////////////////////////////////////////////////////////// // @@ -52,94 +52,220 @@ // ////////////////////////////////////////////////////////////////////////// -//std-trait, fuer alle nicht spezifischen typen: -template < typename T1, typename T2 > -struct UbEqualTrait -{ - using High = T1; - using Low = T1; +// std-trait, fuer alle nicht spezifischen typen: +template <typename T1, typename T2> +struct UbEqualTrait { + using High = T1; + using Low = T1; }; -//std-trait, fuer gleiche T -template < typename T > -struct UbEqualTrait< T, T > -{ - using High = T; - using Low = T; -}; - -//spezialisierung fuer diverse Typen-Tuples -template<> struct UbEqualTrait< short, int > { using High = int; using Low = short; }; -template<> struct UbEqualTrait< short, long > { using High = long; using Low = short; }; -template<> struct UbEqualTrait< short, float > { using High = float; using Low = short; }; -template<> struct UbEqualTrait< short, double > { using High = double; using Low = short; }; -template<> struct UbEqualTrait< short, long double > { using High = long double; using Low = short; }; - -template<> struct UbEqualTrait< int, short > { using High = int; using Low = short; }; -template<> struct UbEqualTrait< int, long > { using High = long; using Low = int; }; -template<> struct UbEqualTrait< int, float > { using High = float; using Low = int; }; -template<> struct UbEqualTrait< int, double > { using High = double; using Low = int; }; -template<> struct UbEqualTrait< int, long double > { using High = long double; using Low = int; }; - -template<> struct UbEqualTrait< long, short > { using High = long; using Low = short; }; -template<> struct UbEqualTrait< long, int > { using High = long; using Low = int; }; -template<> struct UbEqualTrait< long, float > { using High = float; using Low = long; }; -template<> struct UbEqualTrait< long, double > { using High = double; using Low = long; }; -template<> struct UbEqualTrait< long, long double > { using High = long double; using Low = long; }; - -template<> struct UbEqualTrait< float, short > { using High = float; using Low = short; }; -template<> struct UbEqualTrait< float, int > { using High = float; using Low = int; }; -template<> struct UbEqualTrait< float, long > { using High = float; using Low = long; }; -template<> struct UbEqualTrait< float, double > { using High = double; using Low = float; }; -template<> struct UbEqualTrait< float, long double > { using High = long double; using Low = float; }; - -template<> struct UbEqualTrait< double, short > { using High = double; using Low = short; }; -template<> struct UbEqualTrait< double, int > { using High = double; using Low = int; }; -template<> struct UbEqualTrait< double, long > { using High = double; using Low = long; }; -template<> struct UbEqualTrait< double, float > { using High = double; using Low = float; }; -template<> struct UbEqualTrait< double, long double > { using High = long double; using Low = double; }; - -template<> struct UbEqualTrait< long double, short > { using High = long double; using Low = short; }; -template<> struct UbEqualTrait< long double, int > { using High = long double; using Low = int; }; -template<> struct UbEqualTrait< long double, long > { using High = long double; using Low = long; }; -template<> struct UbEqualTrait< long double, float > { using High = long double; using Low = float; }; -template<> struct UbEqualTrait< long double, double > { using High = long double; using Low = double; }; +// std-trait, fuer gleiche T +template <typename T> +struct UbEqualTrait<T, T> { + using High = T; + using Low = T; +}; + +// spezialisierung fuer diverse Typen-Tuples +template <> +struct UbEqualTrait<short, int> { + using High = int; + using Low = short; +}; +template <> +struct UbEqualTrait<short, long> { + using High = long; + using Low = short; +}; +template <> +struct UbEqualTrait<short, float> { + using High = float; + using Low = short; +}; +template <> +struct UbEqualTrait<short, double> { + using High = double; + using Low = short; +}; +template <> +struct UbEqualTrait<short, long double> { + using High = long double; + using Low = short; +}; + +template <> +struct UbEqualTrait<int, short> { + using High = int; + using Low = short; +}; +template <> +struct UbEqualTrait<int, long> { + using High = long; + using Low = int; +}; +template <> +struct UbEqualTrait<int, float> { + using High = float; + using Low = int; +}; +template <> +struct UbEqualTrait<int, double> { + using High = double; + using Low = int; +}; +template <> +struct UbEqualTrait<int, long double> { + using High = long double; + using Low = int; +}; + +template <> +struct UbEqualTrait<long, short> { + using High = long; + using Low = short; +}; +template <> +struct UbEqualTrait<long, int> { + using High = long; + using Low = int; +}; +template <> +struct UbEqualTrait<long, float> { + using High = float; + using Low = long; +}; +template <> +struct UbEqualTrait<long, double> { + using High = double; + using Low = long; +}; +template <> +struct UbEqualTrait<long, long double> { + using High = long double; + using Low = long; +}; + +template <> +struct UbEqualTrait<float, short> { + using High = float; + using Low = short; +}; +template <> +struct UbEqualTrait<float, int> { + using High = float; + using Low = int; +}; +template <> +struct UbEqualTrait<float, long> { + using High = float; + using Low = long; +}; +template <> +struct UbEqualTrait<float, double> { + using High = double; + using Low = float; +}; +template <> +struct UbEqualTrait<float, long double> { + using High = long double; + using Low = float; +}; + +template <> +struct UbEqualTrait<double, short> { + using High = double; + using Low = short; +}; +template <> +struct UbEqualTrait<double, int> { + using High = double; + using Low = int; +}; +template <> +struct UbEqualTrait<double, long> { + using High = double; + using Low = long; +}; +template <> +struct UbEqualTrait<double, float> { + using High = double; + using Low = float; +}; +template <> +struct UbEqualTrait<double, long double> { + using High = long double; + using Low = double; +}; + +template <> +struct UbEqualTrait<long double, short> { + using High = long double; + using Low = short; +}; +template <> +struct UbEqualTrait<long double, int> { + using High = long double; + using Low = int; +}; +template <> +struct UbEqualTrait<long double, long> { + using High = long double; + using Low = long; +}; +template <> +struct UbEqualTrait<long double, float> { + using High = long double; + using Low = float; +}; +template <> +struct UbEqualTrait<long double, double> { + using High = long double; + using Low = double; +}; ////////////////////////////////////////////////////////////////////////// -//fuer Allgmeine-Typen ( operator== ): -template< typename T1, typename T2 > -inline bool specific_equal(const T1& a, const T2& b) { return a==b; } +// fuer Allgmeine-Typen ( operator== ): +template <typename T1, typename T2> +inline bool specific_equal(const T1 &a, const T2 &b) +{ + return a == b; +} ////////////////////////////////////////////////////////////////////////// -//fuer floating point build-in-type -//float.float -template< /*float,float*/> -inline bool specific_equal< float, float >(const float& a, const float& b) { return std::fabs( a - b ) < 1E-8; } +// fuer floating point build-in-type +// float.float +template </*float,float*/> +inline bool specific_equal<float, float>(const float &a, const float &b) +{ + return std::fabs(a - b) < 1E-8; +} -template</*double,double*/> -inline bool specific_equal< double, double >(const double& a, const double& b) { return std::fabs( a - b ) < 1E-13; } +template </*double,double*/> +inline bool specific_equal<double, double>(const double &a, const double &b) +{ + return std::fabs(a - b) < 1E-13; +} -template</*long double,long double*/> -inline bool specific_equal< long double, long double >(const long double& a, const long double& b) { return std::fabs( a - b ) < 1E-16; } +template </*long double,long double*/> +inline bool specific_equal<long double, long double>(const long double &a, const long double &b) +{ + return std::fabs(a - b) < 1E-16; +} ////////////////////////////////////////////////////////////////////////// -//globale isUbEqual - Funktion -template< typename T1, typename T2 > -inline bool isUbEqual(const T1& a, const T2& b) +// globale isUbEqual - Funktion +template <typename T1, typename T2> +inline bool isUbEqual(const T1 &a, const T2 &b) { - using Low = typename UbEqualTrait<T1, T2>::Low; - return specific_equal< Low, Low >(static_cast< Low >( a ),static_cast< Low >( b )); + using Low = typename UbEqualTrait<T1, T2>::Low; + return specific_equal<Low, Low>(static_cast<Low>(a), static_cast<Low>(b)); }; ////////////////////////////////////////////////////////////////////////// -//UbEqual-Functor -template< typename T1, typename T2 > -struct UbEqual -{ - bool operator()(const T1& a, const T2& b) - { - return isUbEqual(a,b); - } +// UbEqual-Functor +template <typename T1, typename T2> +struct UbEqual { + bool operator()(const T1 &a, const T2 &b) { return isUbEqual(a, b); } }; -#endif //UBEQUAL_H +#endif // UBEQUAL_H diff --git a/src/basics/basics/utilities/UbException.h b/src/basics/basics/utilities/UbException.h index 7c625c33f..9a4589806 100644 --- a/src/basics/basics/utilities/UbException.h +++ b/src/basics/basics/utilities/UbException.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,11 +33,11 @@ #ifndef UBEXCEPTION_H #define UBEXCEPTION_H -#include <vector> #include <iostream> -#include <string> #include <sstream> #include <stdexcept> +#include <string> +#include <vector> #include "./UbTuple.h" @@ -51,127 +51,115 @@ // //========================================================================= -//Macro UB_FUNCTION: figures out the method/function name (platform dependant) +// Macro UB_FUNCTION: figures out the method/function name (platform dependant) #if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) - # define UB_FUNCTION __PRETTY_FUNCTION__ +#define UB_FUNCTION __PRETTY_FUNCTION__ #elif defined(__DMC__) && (__DMC__ >= 0x810) - # define UB_FUNCTION __PRETTY_FUNCTION__ +#define UB_FUNCTION __PRETTY_FUNCTION__ #elif defined(__FUNCSIG__) - # define UB_FUNCTION __FUNCSIG__ +#define UB_FUNCTION __FUNCSIG__ #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) - # define UB_FUNCTION __FUNCTION__ +#define UB_FUNCTION __FUNCTION__ #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) - # define UB_FUNCTION __FUNC__ +#define UB_FUNCTION __FUNC__ #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) - # define UB_FUNCTION __func__ +#define UB_FUNCTION __func__ #else - # define UB_FUNCTION "(unknown)" +#define UB_FUNCTION "(unknown)" #endif -//Helper Marco -#define UB_EXARGS __FILE__,__LINE__,UB_FUNCTION +// Helper Marco +#define UB_EXARGS __FILE__, __LINE__, UB_FUNCTION #ifdef CAB_BOOST - #define UB_THROW(e) throw boost::enable_current_exception(e) +#define UB_THROW(e) throw boost::enable_current_exception(e) #else - #define UB_THROW(e) throw e +#define UB_THROW(e) throw e #endif class UbException : public std::runtime_error { public: - using ExceptionData = UbTuple<std::string, int, std::string, std::string>; + using ExceptionData = UbTuple<std::string, int, std::string, std::string>; + public: - ////////////////////////////////////////////////////////////////////////// - //constructors - UbException() - : std::runtime_error("") - { - } - /*==========================================================*/ - UbException(const std::string& str) - : std::runtime_error("") - { - this->addInfo(str); - } - /*==========================================================*/ - UbException(const std::string& file, const int& line, const std::string& err_str) - : std::runtime_error("") - { - this->addInfo(file,line,"unknown",err_str); - } - /*==========================================================*/ - //UbException(const char* file, const int& line, const char* function, const std::string& err_str) - UbException(const std::string& file, const int& line, const std::string& function, const std::string& err_str) - : std::runtime_error("") - { - this->addInfo(file,line,function,err_str); - } - ////////////////////////////////////////////////////////////////////////// - //destructor - ~UbException() noexcept override = default; - ////////////////////////////////////////////////////////////////////////// - //virtual public methods - //returns exception-string - const char* what() const noexcept override - { - exceptionString = this->toString(); - return exceptionString.c_str(); //ansonsten ist das Verhalten anschliessend undefiniert! - } - /*==========================================================*/ - virtual void addInfo(const std::string& err_str) - { - exceptionData.push_back( makeUbTuple( (std::string)"-", 0, (std::string)"unknown", err_str) ); - } - /*==========================================================*/ - //add exception - virtual void addInfo(const std::string& file, const int& line, const std::string& function, const std::string& err_str) - { - exceptionData.push_back( makeUbTuple( file, line, function, err_str ) ); - } - /*==========================================================*/ - //returns exception-string with all calles exceptions - virtual const std::vector<std::string> getInfo() const - { - std::vector<std::string> tmp; - for(std::size_t i=0; i<exceptionData.size(); i++) - { - std::stringstream str; - str << val<1>( exceptionData[i] ) << ", " - << val<2>( exceptionData[i] ) << ", " - << val<3>( exceptionData[i] ) << ", " - << val<4>( exceptionData[i] ); - tmp.push_back( str.str()); - } - return tmp; - } - /*==========================================================*/ - //returns exception-string with all calles exceptions and detailes informations - virtual std::string toString() const - { - std::stringstream str("UbExeption"); - - for(std::size_t i=0; i<exceptionData.size(); i++) - str<<(std::string)"caller[" << i << "]\n" - <<" - file: "<< val<1>( exceptionData[i] )<<"\n" - <<" - line: "<< val<2>( exceptionData[i] )<<"\n" - <<" - function: "<< val<3>( exceptionData[i] )<<"\n" - <<" - what: "<< val<4>( exceptionData[i] )<< std::endl; + ////////////////////////////////////////////////////////////////////////// + // constructors + UbException() : std::runtime_error("") {} + /*==========================================================*/ + UbException(const std::string &str) : std::runtime_error("") { this->addInfo(str); } + /*==========================================================*/ + UbException(const std::string &file, const int &line, const std::string &err_str) : std::runtime_error("") + { + this->addInfo(file, line, "unknown", err_str); + } + /*==========================================================*/ + // UbException(const char* file, const int& line, const char* function, const std::string& err_str) + UbException(const std::string &file, const int &line, const std::string &function, const std::string &err_str) + : std::runtime_error("") + { + this->addInfo(file, line, function, err_str); + } + ////////////////////////////////////////////////////////////////////////// + // destructor + ~UbException() noexcept override = default; + ////////////////////////////////////////////////////////////////////////// + // virtual public methods + // returns exception-string + const char *what() const noexcept override + { + exceptionString = this->toString(); + return exceptionString.c_str(); // ansonsten ist das Verhalten anschliessend undefiniert! + } + /*==========================================================*/ + virtual void addInfo(const std::string &err_str) + { + exceptionData.push_back(makeUbTuple((std::string) "-", 0, (std::string) "unknown", err_str)); + } + /*==========================================================*/ + // add exception + virtual void addInfo(const std::string &file, const int &line, const std::string &function, + const std::string &err_str) + { + exceptionData.push_back(makeUbTuple(file, line, function, err_str)); + } + /*==========================================================*/ + // returns exception-string with all calles exceptions + virtual const std::vector<std::string> getInfo() const + { + std::vector<std::string> tmp; + for (std::size_t i = 0; i < exceptionData.size(); i++) { + std::stringstream str; + str << val<1>(exceptionData[i]) << ", " << val<2>(exceptionData[i]) << ", " << val<3>(exceptionData[i]) + << ", " << val<4>(exceptionData[i]); + tmp.push_back(str.str()); + } + return tmp; + } + /*==========================================================*/ + // returns exception-string with all calles exceptions and detailes informations + virtual std::string toString() const + { + std::stringstream str("UbExeption"); - return str.str(); - } + for (std::size_t i = 0; i < exceptionData.size(); i++) + str << (std::string) "caller[" << i << "]\n" + << " - file: " << val<1>(exceptionData[i]) << "\n" + << " - line: " << val<2>(exceptionData[i]) << "\n" + << " - function: " << val<3>(exceptionData[i]) << "\n" + << " - what: " << val<4>(exceptionData[i]) << std::endl; + + return str.str(); + } protected: - ////////////////////////////////////////////////////////////////////////// - //protected member - std::vector< ExceptionData > exceptionData; - mutable std::string exceptionString; + ////////////////////////////////////////////////////////////////////////// + // protected member + std::vector<ExceptionData> exceptionData; + mutable std::string exceptionString; }; -//overlading operator << -inline std::ostream& operator<<(std::ostream& os, const UbException& e) -{ - return os<<e.toString(); -} +// overlading operator << +inline std::ostream &operator<<(std::ostream &os, const UbException &e) { return os << e.toString(); } -#endif //UBEXCEPTION_H +#endif // UBEXCEPTION_H diff --git a/src/basics/basics/utilities/UbInfinity.h b/src/basics/basics/utilities/UbInfinity.h index 460c439ec..d42b21a42 100644 --- a/src/basics/basics/utilities/UbInfinity.h +++ b/src/basics/basics/utilities/UbInfinity.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -40,41 +40,42 @@ ////////////////////////////////////////////////////////////////////////// //! //! \brief UbNegInfinity -//! \details Note: The UbNegInfinity class cannot be instantiated on its own, but works +//! \details Note: The UbNegInfinity class cannot be instantiated on its own, but works //! as a base class for the Infinity class. //! ////////////////////////////////////////////////////////////////////////// class UbNegInfinity { - public: - //name Conversion operators - inline operator signed char() const { return UbLimits<signed char>::ninf(); } - inline operator char() const { return UbLimits<char>::ninf(); } - inline operator wchar_t() const { return UbLimits<wchar_t>::ninf(); } - inline operator short() const { return UbLimits<short>::ninf(); } - inline operator int() const { return UbLimits<int>::ninf(); } - inline operator long() const { return UbLimits<long>::ninf(); } - inline operator float() const { return UbLimits<float>::ninf(); } - inline operator double() const { return UbLimits<double>::ninf(); } - inline operator long double() const { return UbLimits<long double>::ninf(); } - - //! This function compares built-in data types with their largest possible value. The function - //! only works for built-in data types. The attempt to compare user-defined class types will - //! result in a compile time error. - template< typename T > - inline bool equal( const T& rhs ) const - { - UB_STATIC_ASSERT( std::numeric_limits<T>::is_specialized ); - return UbLimits<T>::ninf() == rhs; - } - protected: +public: + // name Conversion operators + inline operator signed char() const { return UbLimits<signed char>::ninf(); } + inline operator char() const { return UbLimits<char>::ninf(); } + inline operator wchar_t() const { return UbLimits<wchar_t>::ninf(); } + inline operator short() const { return UbLimits<short>::ninf(); } + inline operator int() const { return UbLimits<int>::ninf(); } + inline operator long() const { return UbLimits<long>::ninf(); } + inline operator float() const { return UbLimits<float>::ninf(); } + inline operator double() const { return UbLimits<double>::ninf(); } + inline operator long double() const { return UbLimits<long double>::ninf(); } + + //! This function compares built-in data types with their largest possible value. The function + //! only works for built-in data types. The attempt to compare user-defined class types will + //! result in a compile time error. + template <typename T> + inline bool equal(const T &rhs) const + { + UB_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + return UbLimits<T>::ninf() == rhs; + } + +protected: inline UbNegInfinity() = default; - private: - UbNegInfinity( const UbNegInfinity& ninf ); //copy constructor (private & undefined) - UbNegInfinity& operator=( const UbNegInfinity& ninf ); //copy assignment operator (private & undefined) - void* operator&() const; //address operator (private & undefined) +private: + UbNegInfinity(const UbNegInfinity &ninf); // copy constructor (private & undefined) + UbNegInfinity &operator=(const UbNegInfinity &ninf); // copy assignment operator (private & undefined) + void *operator&() const; // address operator (private & undefined) }; //================================================================================================= @@ -82,28 +83,28 @@ class UbNegInfinity // GLOBAL OPERATORS // //================================================================================================= -template< typename T > -inline bool operator==( const UbNegInfinity& lhs, const T& rhs ) +template <typename T> +inline bool operator==(const UbNegInfinity &lhs, const T &rhs) { - return lhs.equal( rhs ); + return lhs.equal(rhs); } //************************************************************************************************* -template< typename T > -inline bool operator==( const T& lhs, const UbNegInfinity& rhs ) +template <typename T> +inline bool operator==(const T &lhs, const UbNegInfinity &rhs) { - return rhs.equal( lhs ); + return rhs.equal(lhs); } //************************************************************************************************* -template< typename T > -inline bool operator!=( const UbNegInfinity& lhs, const T& rhs ) +template <typename T> +inline bool operator!=(const UbNegInfinity &lhs, const T &rhs) { - return !lhs.equal( rhs ); + return !lhs.equal(rhs); } //************************************************************************************************* -template< typename T > -inline bool operator!=( const T& lhs, const UbNegInfinity& rhs ) +template <typename T> +inline bool operator!=(const T &lhs, const UbNegInfinity &rhs) { - return !rhs.equal( lhs ); + return !rhs.equal(lhs); } ////////////////////////////////////////////////////////////////////////// @@ -111,61 +112,58 @@ inline bool operator!=( const T& lhs, const UbNegInfinity& rhs ) // UbInfinity // ////////////////////////////////////////////////////////////////////////// -class UbInfinity : public UbNegInfinity //um spaeter -UbInfinity leichter zu implementieren!!! +class UbInfinity : public UbNegInfinity // um spaeter -UbInfinity leichter zu implementieren!!! { - public: - inline UbInfinity() - : UbNegInfinity() - {} - - inline operator unsigned char() const { return UbLimits<unsigned char>::inf(); } - inline operator signed char() const { return UbLimits<signed char>::inf(); } - inline operator char() const { return UbLimits<char>::inf(); } - inline operator wchar_t() const { return UbLimits<wchar_t>::inf(); } - inline operator unsigned short() const { return UbLimits<unsigned short>::inf(); } - inline operator short() const { return UbLimits<short>::inf(); } - inline operator unsigned int() const { return UbLimits<unsigned int>::inf(); } - inline operator int() const { return UbLimits<int>::inf(); } - inline operator unsigned long() const { return UbLimits<unsigned long>::inf(); } - inline operator long() const { return UbLimits<long>::inf(); } - inline operator float() const { return UbLimits<float>::inf(); } - inline operator double() const { return UbLimits<double>::inf(); } - inline operator long double() const { return UbLimits<long double>::inf(); } - - inline const UbNegInfinity& operator-() const { return static_cast<const UbNegInfinity&>( *this ); } - - /*==========================================================*/ - template< typename T > - inline bool equal( const T& rhs ) const - { - UB_STATIC_ASSERT( std::numeric_limits<T>::is_specialized ); - return UbLimits<T>::inf() == rhs; - } - - private: - UbInfinity( const UbInfinity& inf ); //Copy constructor (private & undefined) - UbInfinity& operator=( const UbInfinity& inf ); //Copy assignment operator (private & undefined) - void* operator&() const; //Address operator (private & undefined) +public: + inline UbInfinity() : UbNegInfinity() {} + + inline operator unsigned char() const { return UbLimits<unsigned char>::inf(); } + inline operator signed char() const { return UbLimits<signed char>::inf(); } + inline operator char() const { return UbLimits<char>::inf(); } + inline operator wchar_t() const { return UbLimits<wchar_t>::inf(); } + inline operator unsigned short() const { return UbLimits<unsigned short>::inf(); } + inline operator short() const { return UbLimits<short>::inf(); } + inline operator unsigned int() const { return UbLimits<unsigned int>::inf(); } + inline operator int() const { return UbLimits<int>::inf(); } + inline operator unsigned long() const { return UbLimits<unsigned long>::inf(); } + inline operator long() const { return UbLimits<long>::inf(); } + inline operator float() const { return UbLimits<float>::inf(); } + inline operator double() const { return UbLimits<double>::inf(); } + inline operator long double() const { return UbLimits<long double>::inf(); } + + inline const UbNegInfinity &operator-() const { return static_cast<const UbNegInfinity &>(*this); } + + /*==========================================================*/ + template <typename T> + inline bool equal(const T &rhs) const + { + UB_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + return UbLimits<T>::inf() == rhs; + } + +private: + UbInfinity(const UbInfinity &inf); // Copy constructor (private & undefined) + UbInfinity &operator=(const UbInfinity &inf); // Copy assignment operator (private & undefined) + void *operator&() const; // Address operator (private & undefined) }; ////////////////////////////////////////////////////////////////////////// // GLOBAL OPERATORS ////////////////////////////////////////////////////////////////////////// -template< typename T > -inline bool operator==( const UbInfinity& lhs, const T& rhs ); +template <typename T> +inline bool operator==(const UbInfinity &lhs, const T &rhs); -template< typename T > -inline bool operator==( const T& lhs, const UbInfinity& rhs ); +template <typename T> +inline bool operator==(const T &lhs, const UbInfinity &rhs); -template< typename T > -inline bool operator!=( const UbInfinity& lhs, const T& rhs ); +template <typename T> +inline bool operator!=(const UbInfinity &lhs, const T &rhs); -template< typename T > -inline bool operator!=( const T& lhs, const UbInfinity& rhs ); +template <typename T> +inline bool operator!=(const T &lhs, const UbInfinity &rhs); //@} //************************************************************************************************* - //************************************************************************************************* /*!\brief Equality comparison between an Infinity object and a built-in data type. // \ingroup util @@ -173,28 +171,28 @@ inline bool operator!=( const T& lhs, const UbInfinity& rhs ); // This operator works only for built-in data types. The attempt to compare user-defined class // types will result in a compile time error. */ -template< typename T > -inline bool operator==( const UbInfinity& lhs, const T& rhs ) +template <typename T> +inline bool operator==(const UbInfinity &lhs, const T &rhs) { - return lhs.equal( rhs ); + return lhs.equal(rhs); } //************************************************************************************************* -template< typename T > -inline bool operator==( const T& lhs, const UbInfinity& rhs ) +template <typename T> +inline bool operator==(const T &lhs, const UbInfinity &rhs) { - return rhs.equal( lhs ); + return rhs.equal(lhs); } //************************************************************************************************* -template< typename T > -inline bool operator!=( const UbInfinity& lhs, const T& rhs ) +template <typename T> +inline bool operator!=(const UbInfinity &lhs, const T &rhs) { - return !lhs.equal( rhs ); + return !lhs.equal(rhs); } //************************************************************************************************* -template< typename T > -inline bool operator!=( const T& lhs, const UbInfinity& rhs ) +template <typename T> +inline bool operator!=(const T &lhs, const UbInfinity &rhs) { - return !rhs.equal( lhs ); + return !rhs.equal(lhs); } //************************************************************************************************* @@ -203,8 +201,8 @@ inline bool operator!=( const T& lhs, const UbInfinity& rhs ) ////////////////////////////////////////////////////////////////////////// namespace Ub { - //e.g. double x = UbSystem::inf; float x = -Ub::inf; - const UbInfinity inf; -} +// e.g. double x = UbSystem::inf; float x = -Ub::inf; +const UbInfinity inf; +} // namespace Ub -#endif //UB_INFINITY_H +#endif // UB_INFINITY_H diff --git a/src/basics/basics/utilities/UbKeys.h b/src/basics/basics/utilities/UbKeys.h index 29713e756..60dfbf56b 100644 --- a/src/basics/basics/utilities/UbKeys.h +++ b/src/basics/basics/utilities/UbKeys.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,270 +35,274 @@ #include <iostream> - #ifdef CAB_RCF - #include <3rdParty/rcf/RcfSerializationIncludes.h> -#endif //CAB_RCF +#include <3rdParty/rcf/RcfSerializationIncludes.h> +#endif // CAB_RCF ////////////////////////////////////////////////////////////////////////// //! -//! \brief +//! \brief //! namespace for global Keys (e.g. for STL-maps) //! ////////////////////////////////////////////////////////////////////////// namespace UbKeys { - //nested class - template< typename T1, typename T2 = T1 > - class Key2 - { - public: - ////////////////////////////////////////////////////////////////////////// - //Konstruktoren - Key2(const T1& t1, const T2& t2) - : t1(t1), t2(t2) - { - } - /*==========================================================*/ - Key2& operator=(const Key2& srcKey) - { - if(this == &srcKey ) return *this; - - t1 = srcKey.t1; - t2 = srcKey.t2; - - return *this; - } - /*==========================================================*/ - T1 getT1() const { return t1; } - T2 getT2() const { return t2; } - - ////////////////////////////////////////////////////////////////////////// - //global ueberladene Operatoren - friend inline bool operator<(const Key2& lhsKey,const Key2& rhsKey) - { - if( lhsKey.t1 < rhsKey.t1 ) return true; - if( lhsKey.t1 > rhsKey.t1 ) return false; - if( lhsKey.t2 < rhsKey.t2 ) return true; +// nested class +template <typename T1, typename T2 = T1> +class Key2 +{ +public: + ////////////////////////////////////////////////////////////////////////// + // Konstruktoren + Key2(const T1 &t1, const T2 &t2) : t1(t1), t2(t2) {} + /*==========================================================*/ + Key2 &operator=(const Key2 &srcKey) + { + if (this == &srcKey) + return *this; - return false; - } - /*==========================================================*/ - friend inline bool operator==(const Key2& lhsKey, const Key2& rhsKey) - { - if(lhsKey.t1 != rhsKey.t1 ) return false; - if(lhsKey.t2 != rhsKey.t2 ) return false; + t1 = srcKey.t1; + t2 = srcKey.t2; - return true; - } - //ueberladene Operatoren - friend inline bool operator!=(const Key2& lhsKey, const Key2& rhsKey) - { - return !(lhsKey == rhsKey); - } - //ueberladene Operatoren - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, const Key2& key) - { - os<<"Key2<"<<typeid(T1).name()<<","<<typeid(T2).name()<<">,("<<key.t1<<","<<key.t2<<")"; - return os; - } - /*==========================================================*/ - #ifdef CAB_RCF - template<class Archive> - void serialize(Archive & ar, const unsigned int version) - { - ar & t1; - ar & t2; - } - #endif //CAB_RCF + return *this; + } + /*==========================================================*/ + T1 getT1() const { return t1; } + T2 getT2() const { return t2; } - private: - ////////////////////////////////////////////////////////////////////////// - //private Member - T1 t1; - T2 t2; + ////////////////////////////////////////////////////////////////////////// + // global ueberladene Operatoren + friend inline bool operator<(const Key2 &lhsKey, const Key2 &rhsKey) + { + if (lhsKey.t1 < rhsKey.t1) + return true; + if (lhsKey.t1 > rhsKey.t1) + return false; + if (lhsKey.t2 < rhsKey.t2) + return true; - }; + return false; + } + /*==========================================================*/ + friend inline bool operator==(const Key2 &lhsKey, const Key2 &rhsKey) + { + if (lhsKey.t1 != rhsKey.t1) + return false; + if (lhsKey.t2 != rhsKey.t2) + return false; - ////////////////////////////////////////////////////////////////////////// - // - ////////////////////////////////////////////////////////////////////////// - template< typename T1, typename T2 = T1, typename T3 = T1 > - class Key3 - { - public: - ////////////////////////////////////////////////////////////////////////// - //Konstruktoren - Key3() : t1(0), t2(0), t3(0) - { + return true; + } + // ueberladene Operatoren + friend inline bool operator!=(const Key2 &lhsKey, const Key2 &rhsKey) { return !(lhsKey == rhsKey); } + // ueberladene Operatoren + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, const Key2 &key) + { + os << "Key2<" << typeid(T1).name() << "," << typeid(T2).name() << ">,(" << key.t1 << "," << key.t2 << ")"; + return os; + } +/*==========================================================*/ +#ifdef CAB_RCF + template <class Archive> + void serialize(Archive &ar, const unsigned int version) + { + ar &t1; + ar &t2; + } +#endif // CAB_RCF - } - Key3(const T1& t1, const T2& t2, const T3& t3) - : t1(t1), t2(t2), t3(t3) - { - } - /*==========================================================*/ - T1 getT1() const { return t1; } - T2 getT2() const { return t2; } - T3 getT3() const { return t3; } - /*==========================================================*/ - Key3& operator=(const Key3& srcKey) - { - if(this == &srcKey ) return *this; +private: + ////////////////////////////////////////////////////////////////////////// + // private Member + T1 t1; + T2 t2; +}; - t1 = srcKey.t1; - t2 = srcKey.t2; - t3 = srcKey.t3; +////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////// +template <typename T1, typename T2 = T1, typename T3 = T1> +class Key3 +{ +public: + ////////////////////////////////////////////////////////////////////////// + // Konstruktoren + Key3() : t1(0), t2(0), t3(0) {} + Key3(const T1 &t1, const T2 &t2, const T3 &t3) : t1(t1), t2(t2), t3(t3) {} + /*==========================================================*/ + T1 getT1() const { return t1; } + T2 getT2() const { return t2; } + T3 getT3() const { return t3; } + /*==========================================================*/ + Key3 &operator=(const Key3 &srcKey) + { + if (this == &srcKey) + return *this; - return *this; - } + t1 = srcKey.t1; + t2 = srcKey.t2; + t3 = srcKey.t3; - ////////////////////////////////////////////////////////////////////////// - //global ueberladene Operatoren - friend inline bool operator<(const Key3& lhsKey,const Key3& rhsKey) - { - if( lhsKey.t1 < rhsKey.t1 ) return true; - if( lhsKey.t1 > rhsKey.t1 ) return false; - if( lhsKey.t2 < rhsKey.t2 ) return true; - if( lhsKey.t2 > rhsKey.t2 ) return false; - if( lhsKey.t3 < rhsKey.t3 ) return true; + return *this; + } - return false; - } - /*==========================================================*/ - friend inline bool operator==(const Key3& lhsKey,const Key3& rhsKey) - { - if(lhsKey.t1 != rhsKey.t1 ) return false; - if(lhsKey.t2 != rhsKey.t2 ) return false; - if(lhsKey.t3 != rhsKey.t3 ) return false; + ////////////////////////////////////////////////////////////////////////// + // global ueberladene Operatoren + friend inline bool operator<(const Key3 &lhsKey, const Key3 &rhsKey) + { + if (lhsKey.t1 < rhsKey.t1) + return true; + if (lhsKey.t1 > rhsKey.t1) + return false; + if (lhsKey.t2 < rhsKey.t2) + return true; + if (lhsKey.t2 > rhsKey.t2) + return false; + if (lhsKey.t3 < rhsKey.t3) + return true; - return true; - } - /*==========================================================*/ - //ueberladene Operatoren - friend inline bool operator!=(const Key3& lhsKey, const Key3& rhsKey) - { - return !(lhsKey == rhsKey); - } + return false; + } + /*==========================================================*/ + friend inline bool operator==(const Key3 &lhsKey, const Key3 &rhsKey) + { + if (lhsKey.t1 != rhsKey.t1) + return false; + if (lhsKey.t2 != rhsKey.t2) + return false; + if (lhsKey.t3 != rhsKey.t3) + return false; - //ueberladene Operatoren - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, const Key3& key) - { - os<<"Key3<"<<typeid(T1).name()<<","<<typeid(T2).name()<<","<<typeid(T3).name(); - os<<">,("<<key.t1<<","<<key.t2<<","<<key.t3<<")"; - return os; - } - /*==========================================================*/ - #ifdef CAB_RCF - template<class Archive> - void serialize(Archive & ar, const unsigned int version) - { - ar & t1; - ar & t2; - ar & t3; - } - #endif //CAB_RCF + return true; + } + /*==========================================================*/ + // ueberladene Operatoren + friend inline bool operator!=(const Key3 &lhsKey, const Key3 &rhsKey) { return !(lhsKey == rhsKey); } - private: - ////////////////////////////////////////////////////////////////////////// - //private Member - T1 t1; - T2 t2; - T3 t3; - }; + // ueberladene Operatoren + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, const Key3 &key) + { + os << "Key3<" << typeid(T1).name() << "," << typeid(T2).name() << "," << typeid(T3).name(); + os << ">,(" << key.t1 << "," << key.t2 << "," << key.t3 << ")"; + return os; + } +/*==========================================================*/ +#ifdef CAB_RCF + template <class Archive> + void serialize(Archive &ar, const unsigned int version) + { + ar &t1; + ar &t2; + ar &t3; + } +#endif // CAB_RCF - ////////////////////////////////////////////////////////////////////////// - // - ////////////////////////////////////////////////////////////////////////// - template< typename T1, typename T2 = T1, typename T3 = T1, typename T4 = T1 > - class Key4 - { - public: - ////////////////////////////////////////////////////////////////////////// - //Konstruktoren - Key4(const T1& t1, const T2& t2, const T3& t3, const T4& t4) - : t1(t1), t2(t2), t3(t3), t4(t4) - { - } - /*==========================================================*/ - T1 getT1() const { return t1; } - T2 getT2() const { return t2; } - T3 getT3() const { return t3; } - T4 getT4() const { return t4; } - /*==========================================================*/ - Key4& operator=(const Key4& srcKey) - { - if(this == &srcKey ) return *this; +private: + ////////////////////////////////////////////////////////////////////////// + // private Member + T1 t1; + T2 t2; + T3 t3; +}; - t1 = srcKey.t1; - t2 = srcKey.t2; - t3 = srcKey.t3; - t4 = srcKey.t4; +////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////// +template <typename T1, typename T2 = T1, typename T3 = T1, typename T4 = T1> +class Key4 +{ +public: + ////////////////////////////////////////////////////////////////////////// + // Konstruktoren + Key4(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) : t1(t1), t2(t2), t3(t3), t4(t4) {} + /*==========================================================*/ + T1 getT1() const { return t1; } + T2 getT2() const { return t2; } + T3 getT3() const { return t3; } + T4 getT4() const { return t4; } + /*==========================================================*/ + Key4 &operator=(const Key4 &srcKey) + { + if (this == &srcKey) + return *this; - return *this; - } - ////////////////////////////////////////////////////////////////////////// - //global ueberladene Operatoren - friend inline bool operator<(const Key4& lhsKey,const Key4& rhsKey) - { - if( lhsKey.t1 < rhsKey.t1 ) return true; - if( lhsKey.t1 > rhsKey.t1 ) return false; - if( lhsKey.t2 < rhsKey.t2 ) return true; - if( lhsKey.t2 > rhsKey.t2 ) return false; - if( lhsKey.t3 < rhsKey.t3 ) return true; - if( lhsKey.t3 > rhsKey.t3 ) return false; - if( lhsKey.t4 < rhsKey.t4 ) return true; + t1 = srcKey.t1; + t2 = srcKey.t2; + t3 = srcKey.t3; + t4 = srcKey.t4; - return false; - } - /*==========================================================*/ - friend inline bool operator==(const Key4& lhsKey,const Key4& rhsKey) - { - if(lhsKey.t1 != rhsKey.t1 ) return false; - if(lhsKey.t2 != rhsKey.t2 ) return false; - if(lhsKey.t3 != rhsKey.t3 ) return false; - if(lhsKey.t4 != rhsKey.t4 ) return false; + return *this; + } + ////////////////////////////////////////////////////////////////////////// + // global ueberladene Operatoren + friend inline bool operator<(const Key4 &lhsKey, const Key4 &rhsKey) + { + if (lhsKey.t1 < rhsKey.t1) + return true; + if (lhsKey.t1 > rhsKey.t1) + return false; + if (lhsKey.t2 < rhsKey.t2) + return true; + if (lhsKey.t2 > rhsKey.t2) + return false; + if (lhsKey.t3 < rhsKey.t3) + return true; + if (lhsKey.t3 > rhsKey.t3) + return false; + if (lhsKey.t4 < rhsKey.t4) + return true; - return true; - } + return false; + } + /*==========================================================*/ + friend inline bool operator==(const Key4 &lhsKey, const Key4 &rhsKey) + { + if (lhsKey.t1 != rhsKey.t1) + return false; + if (lhsKey.t2 != rhsKey.t2) + return false; + if (lhsKey.t3 != rhsKey.t3) + return false; + if (lhsKey.t4 != rhsKey.t4) + return false; - //ueberladene Operatoren - friend inline bool operator!=(const Key4& lhsKey, const Key4& rhsKey) - { - return !(lhsKey == rhsKey); - } - //ueberladene Operatoren - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, const Key4& key) - { - os<<"Key4<"<<typeid(T1).name()<<","<<typeid(T2).name()<<","<<typeid(T3).name()<<","<<typeid(T4).name(); - os<<">,("<<key.t1<<","<<key.t2<<","<<key.t3<<","<<key.t4<<")"; - return os; - } - /*==========================================================*/ - #ifdef CAB_RCF - template<class Archive> - void serialize(Archive & ar, const unsigned int version) - { - ar & t1; - ar & t2; - ar & t3; - ar & t4; - } - #endif //CAB_RCF + return true; + } - private: - ////////////////////////////////////////////////////////////////////////// - //private Member - T1 t1; - T2 t2; - T3 t3; - T4 t4; + // ueberladene Operatoren + friend inline bool operator!=(const Key4 &lhsKey, const Key4 &rhsKey) { return !(lhsKey == rhsKey); } + // ueberladene Operatoren + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, const Key4 &key) + { + os << "Key4<" << typeid(T1).name() << "," << typeid(T2).name() << "," << typeid(T3).name() << "," + << typeid(T4).name(); + os << ">,(" << key.t1 << "," << key.t2 << "," << key.t3 << "," << key.t4 << ")"; + return os; + } +/*==========================================================*/ +#ifdef CAB_RCF + template <class Archive> + void serialize(Archive &ar, const unsigned int version) + { + ar &t1; + ar &t2; + ar &t3; + ar &t4; + } +#endif // CAB_RCF - }; -} +private: + ////////////////////////////////////////////////////////////////////////// + // private Member + T1 t1; + T2 t2; + T3 t3; + T4 t4; +}; +} // namespace UbKeys -#endif //UBKEYS_H +#endif // UBKEYS_H diff --git a/src/basics/basics/utilities/UbLimits.h b/src/basics/basics/utilities/UbLimits.h index 282ea2c74..385f1f7e9 100644 --- a/src/basics/basics/utilities/UbLimits.h +++ b/src/basics/basics/utilities/UbLimits.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,7 +33,6 @@ #ifndef UB_LIMITS_H #define UB_LIMITS_H - //************************************************************************************************* // Includes //************************************************************************************************* @@ -43,123 +42,111 @@ ////////////////////////////////////////////////////////////////////////// // CLASS DEFINITION ////////////////////////////////////////////////////////////////////////// -template< typename T > -struct UbLimits {}; +template <typename T> +struct UbLimits { +}; ////////////////////////////////////////////////////////////////////////// // SPECIALIZATIONS ////////////////////////////////////////////////////////////////////////// -template<> -struct UbLimits<unsigned char> -{ - //return the largest possible positive unsigned char value - static inline unsigned char inf() { return std::numeric_limits<unsigned char>::max(); } +template <> +struct UbLimits<unsigned char> { + // return the largest possible positive unsigned char value + static inline unsigned char inf() { return std::numeric_limits<unsigned char>::max(); } }; //************************************************************************************************* -template<> -struct UbLimits<char> -{ - //return the largest possible positive char value. */ - static inline char inf () { return std::numeric_limits<char>::max(); } - //return the largest possible negative char value - static inline char ninf() { return std::numeric_limits<char>::min(); } +template <> +struct UbLimits<char> { + // return the largest possible positive char value. */ + static inline char inf() { return std::numeric_limits<char>::max(); } + // return the largest possible negative char value + static inline char ninf() { return std::numeric_limits<char>::min(); } }; //************************************************************************************************* -template<> -struct UbLimits<signed char> -{ - //return the largest possible positive signed char value - static inline signed char inf () { return std::numeric_limits<signed char>::max(); } +template <> +struct UbLimits<signed char> { + // return the largest possible positive signed char value + static inline signed char inf() { return std::numeric_limits<signed char>::max(); } - //return The largest possible negative signed char value - static inline signed char ninf() { return std::numeric_limits<signed char>::min(); } + // return The largest possible negative signed char value + static inline signed char ninf() { return std::numeric_limits<signed char>::min(); } }; //************************************************************************************************* -template<> -struct UbLimits<wchar_t> -{ - //return The largest possible positive wchar_t value - static inline wchar_t inf () { return std::numeric_limits<wchar_t>::max(); } - //return The largest possible negative wchar_t value - static inline wchar_t ninf() { return std::numeric_limits<wchar_t>::min(); } +template <> +struct UbLimits<wchar_t> { + // return The largest possible positive wchar_t value + static inline wchar_t inf() { return std::numeric_limits<wchar_t>::max(); } + // return The largest possible negative wchar_t value + static inline wchar_t ninf() { return std::numeric_limits<wchar_t>::min(); } }; //************************************************************************************************* -template<> -struct UbLimits<unsigned short> -{ - //return The largest possible positive unsigned short value - static inline unsigned short inf() { return std::numeric_limits<unsigned short>::max(); } +template <> +struct UbLimits<unsigned short> { + // return The largest possible positive unsigned short value + static inline unsigned short inf() { return std::numeric_limits<unsigned short>::max(); } }; //************************************************************************************************* -template<> -struct UbLimits<short> -{ - //return The largest possible positive short value - static inline short inf () { return std::numeric_limits<short>::max(); } - //return The largest possible negative short value - static inline short ninf() { return std::numeric_limits<short>::min(); } +template <> +struct UbLimits<short> { + // return The largest possible positive short value + static inline short inf() { return std::numeric_limits<short>::max(); } + // return The largest possible negative short value + static inline short ninf() { return std::numeric_limits<short>::min(); } }; //************************************************************************************************* -template<> -struct UbLimits<unsigned int> -{ - //return The largest possible positive unsigned int value - static inline unsigned int inf() { return std::numeric_limits<unsigned int>::max(); } +template <> +struct UbLimits<unsigned int> { + // return The largest possible positive unsigned int value + static inline unsigned int inf() { return std::numeric_limits<unsigned int>::max(); } }; //************************************************************************************************* -template<> -struct UbLimits<int> -{ - //return The largest possible positive int value - static inline int inf () { return std::numeric_limits<int>::max(); } +template <> +struct UbLimits<int> { + // return The largest possible positive int value + static inline int inf() { return std::numeric_limits<int>::max(); } - //return The largest possible negative int value - static inline int ninf() { return std::numeric_limits<int>::min(); } + // return The largest possible negative int value + static inline int ninf() { return std::numeric_limits<int>::min(); } }; //************************************************************************************************* -template<> -struct UbLimits<unsigned long> -{ - //return The largest possible positive unsigned long value - static inline unsigned long inf() { return std::numeric_limits<unsigned long>::max(); } +template <> +struct UbLimits<unsigned long> { + // return The largest possible positive unsigned long value + static inline unsigned long inf() { return std::numeric_limits<unsigned long>::max(); } }; //************************************************************************************************* -template<> -struct UbLimits<long> -{ - //return The largest possible positive long value - static inline long inf () { return std::numeric_limits<long>::max(); } +template <> +struct UbLimits<long> { + // return The largest possible positive long value + static inline long inf() { return std::numeric_limits<long>::max(); } - //return The largest possible negative long value - static inline long ninf() { return std::numeric_limits<long>::min(); } + // return The largest possible negative long value + static inline long ninf() { return std::numeric_limits<long>::min(); } }; //************************************************************************************************* -template<> -struct UbLimits<float> -{ - //return The largest possible positive float value - static inline float inf () { return std::numeric_limits<float>::max(); } +template <> +struct UbLimits<float> { + // return The largest possible positive float value + static inline float inf() { return std::numeric_limits<float>::max(); } - //return The largest possible negative float value - static inline float ninf() { return -std::numeric_limits<float>::max(); } + // return The largest possible negative float value + static inline float ninf() { return -std::numeric_limits<float>::max(); } }; //************************************************************************************************* -template<> -struct UbLimits<double> -{ - //return The largest possible positive double value - static inline double inf () { return std::numeric_limits<double>::max(); } - //return The largest possible negative double value - static inline double ninf() { return -std::numeric_limits<double>::max(); } +template <> +struct UbLimits<double> { + // return The largest possible positive double value + static inline double inf() { return std::numeric_limits<double>::max(); } + // return The largest possible negative double value + static inline double ninf() { return -std::numeric_limits<double>::max(); } }; //************************************************************************************************* -template<> -struct UbLimits<long double> -{ - //return The largest possible positive long double value - static inline long double inf () { return std::numeric_limits<long double>::max(); } - //return The largest possible negative long double value - static inline long double ninf() { return -std::numeric_limits<long double>::max(); } +template <> +struct UbLimits<long double> { + // return The largest possible positive long double value + static inline long double inf() { return std::numeric_limits<long double>::max(); } + // return The largest possible negative long double value + static inline long double ninf() { return -std::numeric_limits<long double>::max(); } }; -#endif //UB_LIMITS_H +#endif // UB_LIMITS_H diff --git a/src/basics/basics/utilities/UbLogger.cpp b/src/basics/basics/utilities/UbLogger.cpp index 29834020f..b8c28cd0d 100644 --- a/src/basics/basics/utilities/UbLogger.cpp +++ b/src/basics/basics/utilities/UbLogger.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -37,4 +37,3 @@ boost::mutex Output2Stream::mtx; #endif // CAB_BOOST - diff --git a/src/basics/basics/utilities/UbLogger.h b/src/basics/basics/utilities/UbLogger.h index e30157cb5..d350a7637 100644 --- a/src/basics/basics/utilities/UbLogger.h +++ b/src/basics/basics/utilities/UbLogger.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,53 +33,52 @@ #ifndef UBLOGGER_H #define UBLOGGER_H -#include <sstream> -#include <string> -#include <iostream> #include <fstream> #include <iomanip> +#include <iostream> +#include <sstream> +#include <string> -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__WIN64__) - #include <windows.h> +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__WIN64__) +#include <windows.h> #else - #include <sys/time.h> +#include <sys/time.h> #endif #if defined(CAB_BOOST) && !defined(NO_THREADSAFE_LOGGING) - #include <boost/thread.hpp> +#include <boost/thread.hpp> #endif // CAB_BOOST - - -enum LogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5}; +enum LogLevel { logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5 }; ////////////////////////////////////////////////////////////////////////// // template <typename OutputPolicy> class Log - declaration ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// //! -//! \brief +//! \brief //! C++ Logger //! \details Functionality: //! Per logentry an object of type UbLogger is generated, the log string is passed to this object and -//! upon destruction of the object the string is written to a file or the screen depending on +//! upon destruction of the object the string is written to a file or the screen depending on //! the policy (=template paramter). Multiple log level are supported. //! //! helpermakro: UBLOG //! -//! Example 1: +//! Example 1: //! \code -//! UBLOG(logINFO) << "Klasse::foo entered"; //endl is not required +//! UBLOG(logINFO) << "Klasse::foo entered"; //endl is not required //! \endcode //! -//! Example 2: +//! Example 2: //! \code //! try //! { //! UbLog::reportingLevel() = UbLog::logLevelFromString("DEBUG3"); //! //UbLog::output_policy::setStream(&std::cerr); //<- clog is stdandard -//! UbLog::output_policy::setStream("c:/temp/out.txt"); //you can not open these -> error message -> log is output in cerr -//! +//! UbLog::output_policy::setStream("c:/temp/out.txt"); //you can not open these -> error message -> log is output +//! in cerr +//! //! int count = 3; //! UBLOG(logINFO, "A loop with " << count << " iterations"); //! for (int i = 0; i != count; ++i) @@ -100,7 +99,7 @@ enum LogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, lo //! UBLOG(logERROR) << e.what(); //! } //! \endcode -//! Idee based on: +//! Idee based on: //! Paper by Dr. Dobbs Portal, //! September 05, 2007, //! Logging In C++ @@ -108,20 +107,22 @@ enum LogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, lo ////////////////////////////////////////////////////////////////////////// template <typename OutputPolicy> class UbLogger -{ +{ public: - using output_policy = OutputPolicy; + using output_policy = OutputPolicy; + public: UbLogger(); virtual ~UbLogger(); - std::ostringstream& get(const LogLevel& level = logINFO); + std::ostringstream &get(const LogLevel &level = logINFO); + public: - //static, weil man so spaeter die ObjErstellunge ersparen kann, - //falls level kleiner als Level - static LogLevel& reportingLevel(); - - static std::string logLevelToString(const LogLevel& level); - static LogLevel logLevelFromString(const std::string& level); + // static, weil man so spaeter die ObjErstellunge ersparen kann, + // falls level kleiner als Level + static LogLevel &reportingLevel(); + + static std::string logLevelToString(const LogLevel &level); + static LogLevel logLevelFromString(const std::string &level); static std::string logTimeString(); @@ -129,27 +130,26 @@ protected: std::ostringstream os; private: - UbLogger(const UbLogger&); - UbLogger& operator =(const UbLogger&); + UbLogger(const UbLogger &); + UbLogger &operator=(const UbLogger &); }; ////////////////////////////////////////////////////////////////////////// // template <typename OutputPolicy> class Log - implementation ////////////////////////////////////////////////////////////////////////// template <typename OutputPolicy> -UbLogger<OutputPolicy>::UbLogger() -= default; +UbLogger<OutputPolicy>::UbLogger() = default; /*==========================================================*/ template <typename OutputPolicy> -std::ostringstream& UbLogger<OutputPolicy>::get(const LogLevel& level) +std::ostringstream &UbLogger<OutputPolicy>::get(const LogLevel &level) { - os << logTimeString() << " " << std::setw(6) + os << logTimeString() << " " << std::setw(6) #if defined(CAB_BOOST) && !defined(NO_MT_LOGGING) - <<boost::this_thread::get_id() << " " + << boost::this_thread::get_id() << " " #endif - << std::setw(8) << std::left << UbLogger<OutputPolicy>::logLevelToString(level) << ": " - << std::string(level > logDEBUG ? 3*(level - logDEBUG) : 0, ' '); //<baumartiger output :D - + << std::setw(8) << std::left << UbLogger<OutputPolicy>::logLevelToString(level) << ": " + << std::string(level > logDEBUG ? 3 * (level - logDEBUG) : 0, ' '); //<baumartiger output :D + return os; } /*==========================================================*/ @@ -161,72 +161,82 @@ UbLogger<OutputPolicy>::~UbLogger() } /*==========================================================*/ template <typename OutputPolicy> -LogLevel& UbLogger<OutputPolicy>::reportingLevel() +LogLevel &UbLogger<OutputPolicy>::reportingLevel() { static LogLevel reportLevel = logINFO; return reportLevel; } /*==========================================================*/ template <typename OutputPolicy> -std::string UbLogger<OutputPolicy>::logLevelToString(const LogLevel& level) +std::string UbLogger<OutputPolicy>::logLevelToString(const LogLevel &level) { - static std::string const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4", "DEBUG5"}; - return buffer[level]; + static std::string const buffer[] = { "ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", + "DEBUG2", "DEBUG3", "DEBUG4", "DEBUG5" }; + return buffer[level]; } /*==========================================================*/ template <typename OutputPolicy> -LogLevel UbLogger<OutputPolicy>::logLevelFromString(const std::string& level) +LogLevel UbLogger<OutputPolicy>::logLevelFromString(const std::string &level) { - if (level == "DEBUG5" ) return logDEBUG5; - if (level == "DEBUG4" ) return logDEBUG4; - if (level == "DEBUG3" ) return logDEBUG3; - if (level == "DEBUG2" ) return logDEBUG2; - if (level == "DEBUG1" ) return logDEBUG1; - if (level == "DEBUG" ) return logDEBUG; - if (level == "INFO" ) return logINFO; - if (level == "WARNING") return logWARNING; - if (level == "ERROR" ) return logERROR; - - UbLogger<OutputPolicy>().get(logWARNING) << "UbLogger<OutputPolicy>::logLevelFromString(level) - unknown logging level '" << level << "'. Using INFO level as default."; - return logINFO; + if (level == "DEBUG5") + return logDEBUG5; + if (level == "DEBUG4") + return logDEBUG4; + if (level == "DEBUG3") + return logDEBUG3; + if (level == "DEBUG2") + return logDEBUG2; + if (level == "DEBUG1") + return logDEBUG1; + if (level == "DEBUG") + return logDEBUG; + if (level == "INFO") + return logINFO; + if (level == "WARNING") + return logWARNING; + if (level == "ERROR") + return logERROR; + + UbLogger<OutputPolicy>().get(logWARNING) + << "UbLogger<OutputPolicy>::logLevelFromString(level) - unknown logging level '" << level + << "'. Using INFO level as default."; + return logINFO; } ////////////////////////////////////////////////////////////////////////// // logTimeString ////////////////////////////////////////////////////////////////////////// -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__WIN64__) +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__WIN64__) template <typename OutputPolicy> inline std::string UbLogger<OutputPolicy>::logTimeString() { - const int MAX_LEN = 200; - char buffer[MAX_LEN]; - if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, "HH':'mm':'ss", buffer, MAX_LEN) == 0 ) - { - return "Error in std::string UbLogger<OutputPolicy>::logTimeString()"; - } + const int MAX_LEN = 200; + char buffer[MAX_LEN]; + if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, "HH':'mm':'ss", buffer, MAX_LEN) == 0) { + return "Error in std::string UbLogger<OutputPolicy>::logTimeString()"; + } - char result[100] = {0}; - static DWORD first = GetTickCount(); - std::sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); - return result; + char result[100] = { 0 }; + static DWORD first = GetTickCount(); + std::sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); + return result; } #else template <typename OutputPolicy> inline std::string UbLogger<OutputPolicy>::logTimeString() { - char buffer[11]; - time_t t; - time(&t); - tm r = {0}; - strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); - struct timeval tv; - gettimeofday(&tv, 0); - char result[100] = {0}; - std::sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); - return result; + char buffer[11]; + time_t t; + time(&t); + tm r = { 0 }; + strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); + struct timeval tv; + gettimeofday(&tv, 0); + char result[100] = { 0 }; + std::sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); + return result; } -#endif - +#endif ////////////////////////////////////////////////////////////////////////// //! Implementation of OutputPolicy) @@ -234,140 +244,140 @@ inline std::string UbLogger<OutputPolicy>::logTimeString() class Output2Stream // implementation of OutputPolicy { public: - static std::ostream*& getStream(); - static void output(const std::string& msg); - - //!creates output-file-stream (of file opening fails -> stream is set to std::cerr) - static void setStream(const std::string& filename); - - //!direct set outputstream, gcControl = true -> object will be deleted by Output2Stream - static void setStream(std::ostream* pStream, const bool& gcControl = false); + static std::ostream *&getStream(); + static void output(const std::string &msg); + + //! creates output-file-stream (of file opening fails -> stream is set to std::cerr) + static void setStream(const std::string &filename); + + //! direct set outputstream, gcControl = true -> object will be deleted by Output2Stream + static void setStream(std::ostream *pStream, const bool &gcControl = false); protected: #if defined(CAB_BOOST) && !defined(NO_MT_LOGGING) - static boost::mutex mtx; + static boost::mutex mtx; #endif }; /*==========================================================*/ -inline std::ostream*& Output2Stream::getStream() +inline std::ostream *&Output2Stream::getStream() { - static std::ostream* pStream = &std::clog; - return pStream; + static std::ostream *pStream = &std::clog; + return pStream; } /*==========================================================*/ -inline void Output2Stream::setStream(std::ostream* pFile, const bool& gcControl) +inline void Output2Stream::setStream(std::ostream *pFile, const bool &gcControl) { #if defined(CAB_BOOST) && !defined(NO_MT_LOGGING) - boost::mutex::scoped_lock lock(mtx); + boost::mutex::scoped_lock lock(mtx); #endif - static bool s_gcControl = false; - - if( s_gcControl && Output2Stream::getStream() ) - { - delete Output2Stream::getStream(); - } - - s_gcControl = gcControl; - - Output2Stream::getStream() = pFile; + static bool s_gcControl = false; + + if (s_gcControl && Output2Stream::getStream()) { + delete Output2Stream::getStream(); + } + + s_gcControl = gcControl; + + Output2Stream::getStream() = pFile; } /*==========================================================*/ -inline void Output2Stream::setStream(const std::string& filename) +inline void Output2Stream::setStream(const std::string &filename) { - std::ofstream* file = new std::ofstream( filename.c_str() ); - if( !(*file) ) - { - delete file; - Output2Stream::setStream(&std::cerr, false); - UbLogger<Output2Stream>().get(logERROR) << " Output2Stream::setStream(const std::string& filename) could not open file " - << filename << " -> std::cerr is used instead " << std::endl; - return; - } - std::cout<<"UbLog writes to "<<filename<<std::endl; - Output2Stream::setStream(file,true); + std::ofstream *file = new std::ofstream(filename.c_str()); + if (!(*file)) { + delete file; + Output2Stream::setStream(&std::cerr, false); + UbLogger<Output2Stream>().get(logERROR) + << " Output2Stream::setStream(const std::string& filename) could not open file " << filename + << " -> std::cerr is used instead " << std::endl; + return; + } + std::cout << "UbLog writes to " << filename << std::endl; + Output2Stream::setStream(file, true); } /*==========================================================*/ -inline void Output2Stream::output(const std::string& msg) +inline void Output2Stream::output(const std::string &msg) { #if defined(CAB_BOOST) && !defined(NO_MT_LOGGING) - boost::mutex::scoped_lock lock(mtx); + boost::mutex::scoped_lock lock(mtx); #endif - std::ostream* pStream = getStream(); - if (!pStream) return; - (*pStream) << msg << std::flush; + std::ostream *pStream = getStream(); + if (!pStream) + return; + (*pStream) << msg << std::flush; } ////////////////////////////////////////////////////////////////////////// // UbLog ////////////////////////////////////////////////////////////////////////// -class UbLog : public UbLogger< Output2Stream > +class UbLog : public UbLogger<Output2Stream> { - }; -//Macro to limit compiler-side maxLevel +// Macro to limit compiler-side maxLevel #ifndef UBLOG_MAX_LEVEL - #define UBLOG_MAX_LEVEL logDEBUG5 +#define UBLOG_MAX_LEVEL logDEBUG5 #endif ////////////////////////////////////////////////////////////////////////// // example UBLOG(logINFO) << "das ist ein log eintrag"; ////////////////////////////////////////////////////////////////////////// -#define UBLOG(level, logtext) \ - if(level <= UBLOG_MAX_LEVEL && level <= UbLog::reportingLevel() && Output2Stream::getStream()) \ - { \ - UbLog().get(level) << logtext; \ - } - +#define UBLOG(level, logtext) \ + if (level <= UBLOG_MAX_LEVEL && level <= UbLog::reportingLevel() && Output2Stream::getStream()) { \ + UbLog().get(level) << logtext; \ + } + ////////////////////////////////////////////////////////////////////////// -//makro 2 fuer korrekten MultiLineOutput (teuer!!) +// makro 2 fuer korrekten MultiLineOutput (teuer!!) // example1: UBLOGML(logINFO, "line1"<<endl<<"line2"<<endl<<"line3" ) // example2: UBLOGML(logINFO, "line1\nline2\nendl\nline3" ) ////////////////////////////////////////////////////////////////////////// -#define UBLOGML(level, multiline) \ - if(level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) ; \ - else \ - { \ - std::ostringstream output; \ - output << multiline; \ - std::istringstream input( output.str() ); \ - while(!input.eof()) \ - { \ - std::string dummy; \ - getline(input,dummy,'\n'); \ - UbLog().get(level) << dummy; \ - } \ - } +#define UBLOGML(level, multiline) \ + if (level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) \ + ; \ + else { \ + std::ostringstream output; \ + output << multiline; \ + std::istringstream input(output.str()); \ + while (!input.eof()) { \ + std::string dummy; \ + getline(input, dummy, '\n'); \ + UbLog().get(level) << dummy; \ + } \ + } ////////////////////////////////////////////////////////////////////////// -//makro3, falls auch bildschirmausgabe erwuenscht +// makro3, falls auch bildschirmausgabe erwuenscht // -> es wird sowohl ins logfile als auch auf den "stream" geschrieben // wenn reporting level und level passen :D -//example1: UBLOG2ML(logINFO, std::cout, "line1"<<endl<<"line2"<<endl<<"line3" ) -//example2: UBLOG2ML(logINFO, std::cout, "line1\nline2\nendl\nline3" ) +// example1: UBLOG2ML(logINFO, std::cout, "line1"<<endl<<"line2"<<endl<<"line3" ) +// example2: UBLOG2ML(logINFO, std::cout, "line1\nline2\nendl\nline3" ) ////////////////////////////////////////////////////////////////////////// -#define UBLOG2(level, stream, text ) \ - if(level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) ; \ - else { stream << text <<std::endl; UbLog().get(level) << text; } +#define UBLOG2(level, stream, text) \ + if (level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) \ + ; \ + else { \ + stream << text << std::endl; \ + UbLog().get(level) << text; \ + } ////////////////////////////////////////////////////////////////////////// -//makro4, wie 3 nur mit multiline -//example: UBLOG2(logINFO, std::cout, "test" ) +// makro4, wie 3 nur mit multiline +// example: UBLOG2(logINFO, std::cout, "test" ) ////////////////////////////////////////////////////////////////////////// -#define UBLOG2ML(level, stream, multiline ) \ - if(level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) ; \ - else \ - { \ - stream << multiline << std::endl; \ - std::ostringstream output; \ - output << multiline; \ - std::istringstream input( output.str() ); \ - while(!input.eof()) \ - { \ - std::string dummy; \ - getline(input,dummy,'\n'); \ - UbLog().get(level) << dummy; \ - } \ - } +#define UBLOG2ML(level, stream, multiline) \ + if (level > UBLOG_MAX_LEVEL || level > UbLog::reportingLevel() || !Output2Stream::getStream()) \ + ; \ + else { \ + stream << multiline << std::endl; \ + std::ostringstream output; \ + output << multiline; \ + std::istringstream input(output.str()); \ + while (!input.eof()) { \ + std::string dummy; \ + getline(input, dummy, '\n'); \ + UbLog().get(level) << dummy; \ + } \ + } ////////////////////////////////////////////////////////////////////////// // example 2 @@ -376,8 +386,9 @@ class UbLog : public UbLogger< Output2Stream > // { // UbLog::reportingLevel() = UbLog::logLevelFromString("DEBUG3"); // //UbLog::output_policy::setStream(&std::cerr); //<- clog ist stdandard -// UbLog::output_policy::setStream("c:/temp/out.txt"); //kann man diese nicht oeffnen -> fehlermeldung -> Log wird in cerr ausgegben -// +// UbLog::output_policy::setStream("c:/temp/out.txt"); //kann man diese nicht oeffnen -> fehlermeldung -> Log wird +// in cerr ausgegben +// // int count = 3; // UBLOG(logINFO, "A loop with " << count << " iterations"); // for (int i = 0; i != count; ++i) @@ -398,5 +409,4 @@ class UbLog : public UbLogger< Output2Stream > // UBLOG(logERROR) << e.what(); // } - -#endif //UBLOGGER_H +#endif // UBLOGGER_H diff --git a/src/basics/basics/utilities/UbMath.cpp b/src/basics/basics/utilities/UbMath.cpp index ffed193fb..d929f55c6 100644 --- a/src/basics/basics/utilities/UbMath.cpp +++ b/src/basics/basics/utilities/UbMath.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,9 +30,8 @@ //! \ingroup utilities //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#include <basics/utilities/UbMath.h> #include <basics/utilities/UbInfinity.h> +#include <basics/utilities/UbMath.h> #include <cstring> //for memcmp - -const double UbMath::PI = 4.0* std::atan(1.0); //3.1415926535897932384626433832795 +const double UbMath::PI = 4.0 * std::atan(1.0); // 3.1415926535897932384626433832795 diff --git a/src/basics/basics/utilities/UbMath.h b/src/basics/basics/utilities/UbMath.h index 195dda399..fe6b01140 100644 --- a/src/basics/basics/utilities/UbMath.h +++ b/src/basics/basics/utilities/UbMath.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,468 +33,474 @@ #ifndef UBMATH_H #define UBMATH_H +#include <basics/utilities/UbEqual.h> +#include <basics/utilities/UbSystem.h> +#include <cassert> #include <cmath> -#include <limits> #include <iostream> -#include <cassert> -#include <basics/utilities/UbSystem.h> -#include <basics/utilities/UbEqual.h> +#include <limits> + +namespace UbMath +{ +extern const double PI; -namespace UbMath -{ - extern const double PI; - - - ////////////////////////////////////////////////////////////////////////// - //Hilfsfunktion fuer Genauigkeit - template< typename T > - struct Epsilon { }; +////////////////////////////////////////////////////////////////////////// +// Hilfsfunktion fuer Genauigkeit +template <typename T> +struct Epsilon { +}; - ////////////////////////////////////////////////////////////////////////// - // SPECIALIZATIONS von Epsilon - ////////////////////////////////////////////////////////////////////////// - template<> - struct Epsilon<double> { static inline double val() { return 1.0E-11; } }; - template<> - struct Epsilon<float> { static inline float val() { return 1.0E-7f; } }; - template<> - struct Epsilon<long double> { static inline long double val() { return 1.0E-15; } }; - template<> - struct Epsilon<int> { static inline int val() { return 0; } }; +////////////////////////////////////////////////////////////////////////// +// SPECIALIZATIONS von Epsilon +////////////////////////////////////////////////////////////////////////// +template <> +struct Epsilon<double> { + static inline double val() { return 1.0E-11; } +}; +template <> +struct Epsilon<float> { + static inline float val() { return 1.0E-7f; } +}; +template <> +struct Epsilon<long double> { + static inline long double val() { return 1.0E-15; } +}; +template <> +struct Epsilon<int> { + static inline int val() { return 0; } +}; + +/*=======================================================*/ +// ------------------------------------------------------------------------------------------------- +// Funktion berechnet den Logarithmus einer Zahl z bzgl. der Basis b +// ------------------------------------------------------------------------------------------------- +template <typename T> +inline T log(const T &z, const T &base) +{ + if (::log(base) == 0) + return 1.0f; + return ::log(z) / ::log(base); +} +/*=======================================================*/ +// double x = UbMath::getNegativeInfinity<double>(); +template <typename T> +inline T getNegativeInfinity() +{ + // assert(std::numeric_limits<T>::has_infinity); + UB_STATIC_ASSERT(std::numeric_limits<T>::has_infinity); + return -std::numeric_limits<T>::infinity(); +} +/*=======================================================*/ +// double x = UbMath::getPositiveInfinity<double>(); +template <typename T> +inline T getPositiveInfinity() +{ + // assert(std::numeric_limits<T>::has_infinity); + UB_STATIC_ASSERT(std::numeric_limits<T>::has_infinity); + return std::numeric_limits<T>::infinity(); +} +/*=======================================================*/ +// double x; bool b = UbMath::isInfinity(x); +template <typename T> +inline bool isInfinity(const T &value) +{ + if (value == getNegativeInfinity<T>()) + return true; + if (value == getPositiveInfinity<T>()) + return true; + return false; +} +/*=======================================================*/ +// double x = UbMath::getNaN<double>(x); +template <typename T> +inline T getNaN() +{ + UB_STATIC_ASSERT(std::numeric_limits<T>::has_quiet_NaN); + return std::numeric_limits<T>::quiet_NaN(); +} +/*=======================================================*/ +// double x; bool b = UbMath::isNaN(x); +// x!=x liefert bei #QNAN "true"! +template <typename T> +inline bool isNaN(const T &x) +{ + UB_STATIC_ASSERT(std::numeric_limits<T>::has_quiet_NaN); + return (x != x); +} +/*=======================================================*/ +template <typename T> +inline T getEqualityEpsilon() +{ + return Epsilon<T>::val(); +} +/*=======================================================*/ +template <typename T> +inline bool zero(const T &value) +{ + return std::fabs(value) < Epsilon<T>::val(); + // return value >= -UbMath::EPSILON && value <= UbMath::EPSILON; +} +/*=======================================================*/ +// spezialisierung fuer ints +template <> +inline bool zero(const int &value) +{ + return value == 0; +} +/*=======================================================*/ +template <typename T1, typename T2> +inline bool zero(const T1 &value1, const T2 &value2) +{ + return !(!UbMath::zero(value1) || !UbMath::zero(value2)); +} +/*=======================================================*/ +template <typename T1, typename T2, typename T3> +inline bool zero(const T1 &value1, const T2 &value2, const T3 &value3) +{ + return !(!UbMath::zero(value1) || !UbMath::zero(value2, value3)); +} +/*=======================================================*/ +template <typename T> +inline bool negative(const T &value) +{ + return value < -Epsilon<T>::val(); +} +/*=======================================================*/ +template <typename T> +inline bool nonPositive(const T &value) +{ + return value <= Epsilon<T>::val(); +} +/*=======================================================*/ +template <typename T> +inline bool positive(const T &value) +{ + return value > +Epsilon<T>::val(); +} +/*=======================================================*/ +template <typename T> +inline bool nonNegative(const T &value) +{ + return value >= -Epsilon<T>::val(); +} +/*=======================================================*/ +template <typename T1, typename T2> +inline bool equal(const T1 &value, const T2 &reference) +{ + using High = typename UbEqualTrait<T1, T2>::High; + return std::fabs(value - reference) < Epsilon<High>::val(); +} +/*=======================================================*/ +template <typename T1, typename T2, typename T3> +inline bool equal(const T1 &val1, const T2 &val2, const T3 &val3) +{ + return (UbMath::equal(val1, val2) && UbMath::equal(val1, val3)); +} +/*=======================================================*/ +template <typename T1, typename T2> +inline bool less(const T1 &value, const T2 &reference) +{ + using High = typename UbEqualTrait<T1, T2>::High; + return value < reference - Epsilon<High>::val(); +} +/*=======================================================*/ +template <typename T1, typename T2> +inline bool lessEqual(const T1 &value, const T2 &reference) +{ + using High = typename UbEqualTrait<T1, T2>::High; + return value <= reference + Epsilon<High>::val(); +} +/*=======================================================*/ +template <typename T1, typename T2> +inline bool greater(const T1 &value, const T2 &reference) +{ + using High = typename UbEqualTrait<T1, T2>::High; + return value > reference + Epsilon<High>::val(); +} +/*=======================================================*/ +template <typename T1, typename T2> +inline bool greaterEqual(const T1 &value, const T2 &reference) +{ + using High = typename UbEqualTrait<T1, T2>::High; + return value >= reference - Epsilon<High>::val(); +} +/*=======================================================*/ +template <typename T> +inline T round(const T &value, const int &decimalPlaces) +{ + return static_cast<T>(floor(value * pow(10.0, decimalPlaces) + 0.5) * pow(10.0, -decimalPlaces)); +} +/*=======================================================*/ +template <typename T> +inline int integerRounding(const T &value) +{ + return static_cast<int>(UbMath::zero(value) ? 0 : ((value < 0.0) ? (value - 0.5) : (value + 0.5))); +} +/*=======================================================*/ +template <typename T> +inline T getRad(const T °rees) +{ + return degrees * static_cast<T>(UbMath::PI / 180.0); +} +/*=======================================================*/ +template <typename T> +inline T getDegrees(const T &rad) +{ + return rad * static_cast<T>(UbMath::PI / 180.0); +} +/*=======================================================*/ +// aus wildmagic +template <typename T> +inline T ACos(const T &fValue) +{ + if (-1.0 < fValue) { + if (fValue < 1.0) + return static_cast<T>(acos(fValue)); + else + return static_cast<T>(0.0); + } else + return static_cast<T>(PI); +} +/*=======================================================*/ +template <typename T> +inline T ASin(const T &fValue) +{ + double HALF_PI = 0.5 * UbMath::PI; + if (-1.0 < fValue) { + if (fValue < 1.0) + return static_cast<T>(asin(fValue)); + else + return static_cast<T>(HALF_PI); + } else + return -static_cast<T>(HALF_PI); +} +/*=======================================================*/ +template <typename T> +inline T invSqrt(const T &fValue) +{ + return static_cast<T>(1.0 / sqrt(fValue)); +} - /*=======================================================*/ - // ------------------------------------------------------------------------------------------------- - // Funktion berechnet den Logarithmus einer Zahl z bzgl. der Basis b - // ------------------------------------------------------------------------------------------------- - template<typename T> - inline T log(const T& z, const T& base) - { - if( ::log(base)==0 ) return 1.0f; - return ::log(z) / ::log(base); - } - /*=======================================================*/ - //double x = UbMath::getNegativeInfinity<double>(); - template<typename T> - inline T getNegativeInfinity() - { - //assert(std::numeric_limits<T>::has_infinity); - UB_STATIC_ASSERT(std::numeric_limits<T>::has_infinity); - return -std::numeric_limits<T>::infinity(); - } - /*=======================================================*/ - //double x = UbMath::getPositiveInfinity<double>(); - template<typename T> - inline T getPositiveInfinity() - { - //assert(std::numeric_limits<T>::has_infinity); - UB_STATIC_ASSERT(std::numeric_limits<T>::has_infinity); - return std::numeric_limits<T>::infinity(); - } - /*=======================================================*/ - //double x; bool b = UbMath::isInfinity(x); - template<typename T> - inline bool isInfinity(const T& value) - { - if(value==getNegativeInfinity<T>()) return true; - if(value==getPositiveInfinity<T>()) return true; - return false; - } - /*=======================================================*/ - //double x = UbMath::getNaN<double>(x); - template<typename T> - inline T getNaN() - { - UB_STATIC_ASSERT(std::numeric_limits<T>::has_quiet_NaN); - return std::numeric_limits<T>::quiet_NaN(); - } - /*=======================================================*/ - //double x; bool b = UbMath::isNaN(x); - // x!=x liefert bei #QNAN "true"! - template<typename T> - inline bool isNaN(const T& x) - { - UB_STATIC_ASSERT(std::numeric_limits<T>::has_quiet_NaN); - return (x != x); - } - /*=======================================================*/ - template<typename T> - inline T getEqualityEpsilon() - { - return Epsilon<T>::val(); - } - /*=======================================================*/ - template<typename T> - inline bool zero(const T& value) - { - return std::fabs( value ) < Epsilon<T>::val(); - //return value >= -UbMath::EPSILON && value <= UbMath::EPSILON; - } - /*=======================================================*/ - //spezialisierung fuer ints - template<> - inline bool zero(const int& value) - { - return value == 0; - } - /*=======================================================*/ - template<typename T1, typename T2> - inline bool zero(const T1& value1, const T2& value2) - { - return !(!UbMath::zero(value1) || !UbMath::zero(value2)); - } - /*=======================================================*/ - template<typename T1, typename T2, typename T3> - inline bool zero(const T1& value1, const T2& value2, const T3& value3) - { - return !(!UbMath::zero(value1) || !UbMath::zero(value2,value3)); - } - /*=======================================================*/ - template<typename T> - inline bool negative(const T& value) - { - return value < -Epsilon<T>::val(); - } - /*=======================================================*/ - template<typename T> - inline bool nonPositive(const T& value) - { - return value <= Epsilon<T>::val(); - } - /*=======================================================*/ - template<typename T> - inline bool positive(const T& value) - { - return value > +Epsilon<T>::val(); - } - /*=======================================================*/ - template<typename T> - inline bool nonNegative(const T& value) - { - return value >= -Epsilon<T>::val(); - } - /*=======================================================*/ - template<typename T1, typename T2> - inline bool equal(const T1& value, const T2& reference) - { - using High = typename UbEqualTrait<T1, T2>::High; - return std::fabs(value-reference) < Epsilon<High>::val(); - } - /*=======================================================*/ - template<typename T1, typename T2, typename T3> - inline bool equal(const T1& val1, const T2& val2, const T3& val3) - { - return ( UbMath::equal(val1,val2) && UbMath::equal(val1,val3) ); - } - /*=======================================================*/ - template<typename T1, typename T2> - inline bool less(const T1& value, const T2& reference) - { - using High = typename UbEqualTrait<T1, T2>::High; - return value < reference - Epsilon<High>::val(); - } - /*=======================================================*/ - template<typename T1, typename T2> - inline bool lessEqual(const T1& value, const T2& reference) - { - using High = typename UbEqualTrait<T1, T2>::High; - return value <= reference + Epsilon<High>::val(); - } - /*=======================================================*/ - template<typename T1, typename T2> - inline bool greater(const T1& value, const T2& reference) - { - using High = typename UbEqualTrait<T1, T2>::High; - return value > reference + Epsilon<High>::val(); - } - /*=======================================================*/ - template<typename T1, typename T2> - inline bool greaterEqual(const T1& value, const T2& reference) - { - using High = typename UbEqualTrait<T1, T2>::High; - return value >= reference - Epsilon<High>::val(); - } - /*=======================================================*/ - template<typename T> - inline T round(const T& value, const int& decimalPlaces) - { - return static_cast<T>(floor(value * pow( 10.0, decimalPlaces) + 0.5 ) * pow(10.0, -decimalPlaces)); - } - /*=======================================================*/ - template<typename T> - inline int integerRounding(const T& value) - { - return static_cast<int>( UbMath::zero(value) ? 0 : ( (value<0.0) ? (value-0.5) : (value+0.5) ) ); - } - /*=======================================================*/ - template<typename T> - inline T getRad(const T& degrees) - { - return degrees*static_cast<T>(UbMath::PI/180.0); - } - /*=======================================================*/ - template<typename T> - inline T getDegrees(const T& rad) - { - return rad*static_cast<T>(UbMath::PI/180.0); - } - /*=======================================================*/ - //aus wildmagic - template<typename T> - inline T ACos (const T& fValue) - { - if ( -1.0 < fValue ) - { - if ( fValue < 1.0 ) return static_cast<T>( acos(fValue) ); - else return static_cast<T>( 0.0 ); - } - else return static_cast<T>( PI ); - } - /*=======================================================*/ - template<typename T> - inline T ASin(const T& fValue) - { - double HALF_PI = 0.5*UbMath::PI; - if ( -1.0 < fValue ) - { - if ( fValue < 1.0 ) return static_cast<T>( asin(fValue) ); - else return static_cast<T>( HALF_PI ); - } - else return -static_cast<T>( HALF_PI ); - } - /*=======================================================*/ - template<typename T> - inline T invSqrt(const T& fValue) - { - return static_cast<T>(1.0/sqrt(fValue)); - } +/*=======================================================*/ +/** + * Returns true, if specified values a and b are less both values c and d. + * @param a the first value to check + * @param b the second value to check + * @param c the first value to check against + * @param d the second value to check against + * @return true, if specified values a and b are less both values c and d + **/ +template <typename T1, typename T2, typename T3, typename T4> +inline bool less2(const T1 &value1, const T2 &value2, T3 toBeLessAs1, T4 toBeLessAs2) +{ + return (less(value1, toBeLessAs1) && less(value1, toBeLessAs2) && less(value2, toBeLessAs1) && + less(value2, toBeLessAs2)); +} +/*=======================================================*/ +template <typename T1, typename T2, typename T3, typename T4> +inline bool greater2(const T1 &value1, const T2 &value2, T3 toBeGreaterAs1, T4 toBeGreaterAs2) +{ + return (greater(value1, toBeGreaterAs1) && greater(value1, toBeGreaterAs2) && greater(value2, toBeGreaterAs1) && + greater(value2, toBeGreaterAs2)); +} +/*=======================================================*/ +template <typename T1, typename T2, typename T3> +inline bool inClosedInterval(const T1 &value, const T2 &threshold1, const T3 &threshold2) +{ + if (threshold1 < threshold2) { + return (greaterEqual(value, threshold1) && lessEqual(value, threshold2)); + } - /*=======================================================*/ - /** - * Returns true, if specified values a and b are less both values c and d. - * @param a the first value to check - * @param b the second value to check - * @param c the first value to check against - * @param d the second value to check against - * @return true, if specified values a and b are less both values c and d - **/ - template<typename T1, typename T2, typename T3, typename T4> - inline bool less2(const T1& value1, const T2& value2, T3 toBeLessAs1, T4 toBeLessAs2) - { - return ( less(value1,toBeLessAs1) - && less(value1,toBeLessAs2) - && less(value2,toBeLessAs1) - && less(value2,toBeLessAs2) ); - } - /*=======================================================*/ - template<typename T1, typename T2, typename T3, typename T4> - inline bool greater2(const T1& value1, const T2& value2, T3 toBeGreaterAs1, T4 toBeGreaterAs2) - { - return ( greater(value1,toBeGreaterAs1) - && greater(value1,toBeGreaterAs2) - && greater(value2,toBeGreaterAs1) - && greater(value2,toBeGreaterAs2) ); - } - /*=======================================================*/ - template<typename T1, typename T2, typename T3> - inline bool inClosedInterval(const T1& value, const T2& threshold1, const T3& threshold2) - { - if(threshold1 < threshold2) - { - return ( greaterEqual( value, threshold1) && lessEqual( value, threshold2) ); - } + return (greaterEqual(value, threshold2) && lessEqual(value, threshold1)); +} +/*=======================================================*/ +template <typename T1, typename T2, typename T3> +inline bool inOpenInterval(const T1 &value, const T2 &threshold1, const T3 &threshold2) +{ + if (threshold1 < threshold2) { + return (greater(value, threshold1) && less(value, threshold2)); + } - return ( greaterEqual( value, threshold2) && lessEqual( value, threshold1) ); - } - /*=======================================================*/ - template<typename T1, typename T2, typename T3> - inline bool inOpenInterval(const T1& value, const T2& threshold1, const T3& threshold2) - { - if(threshold1 < threshold2) - { - return (greater( value, threshold1) && less( value, threshold2)); - } + return (greater(value, threshold2) && less(value, threshold1)); +} +/*=======================================================*/ +template <typename T1, typename T2, typename T3> +inline double adaptToClosedInterval(const T1 &value, const T2 &threshold1, const T3 &threshold2) +{ + if (threshold1 < threshold2) { + if (less(value, threshold1)) + return threshold1; + else if (greater(value, threshold2)) + return threshold2; + } else { + if (less(value, threshold2)) + return threshold2; + else if (greater(value, threshold1)) + return threshold1; + } + return value; +} +/*=======================================================*/ +// ------------------------------------------------------------------------------------------------- +// Funktion berechnet den groessten gemeinsamen Teiler zweier Zahlen (MK) +// ------------------------------------------------------------------------------------------------- +/*=======================================================*/ +inline int calcGgt(int val1, int val2) +{ + if (val1 < val2) + std::swap(val1, val2); + int ggt = val2; + while (ggt > 1) { + if ((val1 % ggt) == 0 && (val2 % ggt) == 0) + break; - return (greater( value, threshold2) && less( value, threshold1)); - } - /*=======================================================*/ - template<typename T1, typename T2, typename T3> - inline double adaptToClosedInterval(const T1& value, const T2& threshold1, const T3& threshold2) - { - if(threshold1 < threshold2) - { - if ( less( value, threshold1) ) return threshold1; - else if( greater(value, threshold2) ) return threshold2; - } - else - { - if ( less( value, threshold2) ) return threshold2; - else if( greater(value, threshold1) ) return threshold1; - } - return value; - } - /*=======================================================*/ - // ------------------------------------------------------------------------------------------------- - // Funktion berechnet den groessten gemeinsamen Teiler zweier Zahlen (MK) - // ------------------------------------------------------------------------------------------------- - /*=======================================================*/ - inline int calcGgt(int val1, int val2) - { - if( val1 < val2 ) std::swap(val1,val2); - int ggt=val2; - while(ggt > 1) - { - if( (val1%ggt)==0 && (val2%ggt)==0 ) break; + ggt -= 1; + } + return ggt; +} +/*=======================================================*/ +// ------------------------------------------------------------------------------------------------- +// Funktion berechnet den groessten gemeinsamen Teiler von drei Zahlen (MK) +// ------------------------------------------------------------------------------------------------- +inline int calcGgt(int val1, const int &val2, int val3) { return UbMath::calcGgt(UbMath::calcGgt(val1, val2), val3); } +/*=======================================================*/ +// returns the max of c2 values +// to avoid errors at mixed argument-types use: double myMax = max<double>(2,2.3); +template <typename T> +inline const T &max(const T &a1, const T &a2) +{ + return (a1 < a2) ? a2 : a1; +} +/*=======================================================*/ +template <typename T> +inline const T &max(const T &a1, const T &a2, const T &a3) +{ + return max(max(a1, a2), a3); +} +/*=======================================================*/ +template <typename T> +inline const T &max(const T &a1, const T &a2, const T &a3, const T &a4) +{ + return max(max(max(a1, a2), a3), a4); +} +/*=======================================================*/ +template <typename T> +inline const T &min(const T &a1, const T &a2) +{ + return (a1 < a2) ? a1 : a2; +} +/*=======================================================*/ +template <typename T> +inline const T &min(const T &a1, const T &a2, const T &a3) +{ + return min(min(a1, a2), a3); +} +/*=======================================================*/ +template <typename T> +inline const T &min(const T &a1, const T &a2, const T &a3, const T &a4) +{ + return min(min(min(a1, a2), a3), a4); - ggt -=1; - } - return ggt; - } - /*=======================================================*/ - // ------------------------------------------------------------------------------------------------- - // Funktion berechnet den groessten gemeinsamen Teiler von drei Zahlen (MK) - // ------------------------------------------------------------------------------------------------- - inline int calcGgt(int val1, const int& val2, int val3) - { - return UbMath::calcGgt( UbMath::calcGgt(val1, val2), val3 ); - } - /*=======================================================*/ - //returns the max of c2 values - //to avoid errors at mixed argument-types use: double myMax = max<double>(2,2.3); - template< typename T > - inline const T& max(const T& a1, const T& a2) - { - return (a1<a2) ? a2 : a1; - } - /*=======================================================*/ - template< typename T > - inline const T& max(const T& a1, const T& a2, const T& a3) - { - return max(max(a1,a2),a3); - } - /*=======================================================*/ - template< typename T > - inline const T& max(const T& a1, const T& a2, const T& a3, const T& a4) - { - return max(max(max(a1,a2),a3),a4); - } - /*=======================================================*/ - template< typename T > - inline const T& min(const T& a1,const T& a2) - { - return (a1<a2) ? a1 : a2; - } - /*=======================================================*/ - template< typename T > - inline const T& min(const T& a1, const T& a2, const T& a3) - { - return min(min(a1,a2),a3); - } - /*=======================================================*/ - template< typename T > - inline const T& min(const T& a1, const T& a2, const T& a3, const T& a4) - { - return min(min(min(a1,a2),a3),a4); - -// double tmp = a1; -// if(tmp>a2) tmp=a2; -// if(tmp>a3) tmp=a3; -// if(tmp>a4) tmp=a4; -// return tmp; - } + // double tmp = a1; + // if(tmp>a2) tmp=a2; + // if(tmp>a3) tmp=a3; + // if(tmp>a4) tmp=a4; + // return tmp; +} - ////////////////////////////////////////////////////////////////////////// - // - //constants - // - ////////////////////////////////////////////////////////////////////////// - static const double c8o27 = 8. / 27.; - static const double c2o27 = 2. / 27.; - static const double c1o54 = 1. / 54.; - static const double c1o216 = 1. / 216.; - static const double c9o2 = 9. / 2.; //4.5 - static const double c9o4 = 9. / 4.; //2.25 - static const double c3o9 = 3. / 9.; - static const double c3o54 = 3. / 54.; - static const double c3o216 = 3. / 216.; +////////////////////////////////////////////////////////////////////////// +// +// constants +// +////////////////////////////////////////////////////////////////////////// +static const double c8o27 = 8. / 27.; +static const double c2o27 = 2. / 27.; +static const double c1o54 = 1. / 54.; +static const double c1o216 = 1. / 216.; +static const double c9o2 = 9. / 2.; // 4.5 +static const double c9o4 = 9. / 4.; // 2.25 +static const double c3o9 = 3. / 9.; +static const double c3o54 = 3. / 54.; +static const double c3o216 = 3. / 216.; - static const double c1o27 = 1. / 27.; +static const double c1o27 = 1. / 27.; - static const double c1o72 = 1. / 72.; //0.01388888 - static const double c1o36 = 1. / 36.; //0.02777777 - static const double c1o48 = 1. / 48.; //0.02083333 - static const double c1o32 = 1. / 32.; //0.03125 - static const double c1o24 = 1. / 24.; //0.04166666 - static const double c1o20 = 1. / 20.; //0.05 - static const double c1o18 = 1. / 18.; //0.05555555 - static const double c1o16 = 1. / 16.; //0.0625 - static const double c1o12 = 1. / 12.; //0.08333333 - static const double c1o9 = 1. / 9.; //0.11111111 - static const double c1o8 = 1. / 8.; //0.125 - static const double c1o6 = 1. / 6.; //0.16666666 - static const double c1o5 = 1. / 5.; //0.2 - static const double c1o4 = 1. / 4.; //0.25 - static const double c1o100 = 1. / 100.; - static const double c5o16 = 5. / 16.; //0.3125 - static const double c1o3 = 1. / 3.; //0.33333333 - static const double c3o8 = 3. / 8.; //0.375 - static const double c4o9 = 4. / 9.; //0.44444444 - static const double c1o2 = 1. / 2.; //0.5 - static const double c9o16 = 9. / 16.; //0.5625 - static const double c2o3 = 2. / 3.; //0.66666666 - static const double c3o4 = 3. / 4.; //0.75 - static const double c3o2 = 3. / 2.; //1.5 - static const double c4o3 = 4. / 3.; //1.33333333 - static const double c5o3 = 5. / 3.; //1.66666666 - static const double c9o5 = 9. / 5.; //1.8 - static const double c2o9 = 2. / 9.; //0.22222222 - static const double one_over_sqrt2 = 1.0 / sqrt(2.0); //0.707106781 - static const double one_over_sqrt3 = 1.0 / sqrt(3.0); //0.577350269 - static const double sqrt2 = sqrt(2.0); //1.4142135 - static const double sqrt3 = sqrt(3.0); //1.7320508 - static const double zeroReal = 0.0; - static const double c1 = 1.0; - static const double c2 = 2.0; - static const double c3 = 3.0; - static const double c4 = 4.0; - static const double c5 = 5.0; - static const double c6 = 6.0; - static const double c7 = 7.0; - static const double c8 = 8.0; - static const double c9 = 9.0; - static const double c14 = 14.0; - static const double c15 = 15.0; - static const double c16 = 16.0; - static const double c18 = 18.0; - static const double c21 = 21.0; - static const double c24 = 24.0; - static const double c28 = 28.0; - static const double c29 = 29.0; - static const double c36 = 36.0; - static const double c48 = 48.0; - static const double c50 = 50.0; - static const double c56 = 56.0; - static const double c152 = 152.0; - static const double c130 = 130.0; - static const double one = 1.0; - static const double two = 2.0; - static const double three = 3.0; - static const double four = 4.0; - static const double five = 5.0; - static const double six = 6.0; - static const double seven = 7.0; - static const double eight = 8.0; - static const double nine = 9.0; - static const double fourteen = 14.0; - static const double fiveteen = 15.0; - static const double sixteen = 16.0; - static const double twentyone = 21.0; - static const double twentyfour = 24.0; - static const double twentyeight = 28.0; - static const double twentynine = 29.0; - static const double fourtyeight = 48.0; - static const double fifty = 50.0; - static const double fiftysix = 56.0; +static const double c1o72 = 1. / 72.; // 0.01388888 +static const double c1o36 = 1. / 36.; // 0.02777777 +static const double c1o48 = 1. / 48.; // 0.02083333 +static const double c1o32 = 1. / 32.; // 0.03125 +static const double c1o24 = 1. / 24.; // 0.04166666 +static const double c1o20 = 1. / 20.; // 0.05 +static const double c1o18 = 1. / 18.; // 0.05555555 +static const double c1o16 = 1. / 16.; // 0.0625 +static const double c1o12 = 1. / 12.; // 0.08333333 +static const double c1o9 = 1. / 9.; // 0.11111111 +static const double c1o8 = 1. / 8.; // 0.125 +static const double c1o6 = 1. / 6.; // 0.16666666 +static const double c1o5 = 1. / 5.; // 0.2 +static const double c1o4 = 1. / 4.; // 0.25 +static const double c1o100 = 1. / 100.; +static const double c5o16 = 5. / 16.; // 0.3125 +static const double c1o3 = 1. / 3.; // 0.33333333 +static const double c3o8 = 3. / 8.; // 0.375 +static const double c4o9 = 4. / 9.; // 0.44444444 +static const double c1o2 = 1. / 2.; // 0.5 +static const double c9o16 = 9. / 16.; // 0.5625 +static const double c2o3 = 2. / 3.; // 0.66666666 +static const double c3o4 = 3. / 4.; // 0.75 +static const double c3o2 = 3. / 2.; // 1.5 +static const double c4o3 = 4. / 3.; // 1.33333333 +static const double c5o3 = 5. / 3.; // 1.66666666 +static const double c9o5 = 9. / 5.; // 1.8 +static const double c2o9 = 2. / 9.; // 0.22222222 +static const double one_over_sqrt2 = 1.0 / sqrt(2.0); // 0.707106781 +static const double one_over_sqrt3 = 1.0 / sqrt(3.0); // 0.577350269 +static const double sqrt2 = sqrt(2.0); // 1.4142135 +static const double sqrt3 = sqrt(3.0); // 1.7320508 +static const double zeroReal = 0.0; +static const double c1 = 1.0; +static const double c2 = 2.0; +static const double c3 = 3.0; +static const double c4 = 4.0; +static const double c5 = 5.0; +static const double c6 = 6.0; +static const double c7 = 7.0; +static const double c8 = 8.0; +static const double c9 = 9.0; +static const double c14 = 14.0; +static const double c15 = 15.0; +static const double c16 = 16.0; +static const double c18 = 18.0; +static const double c21 = 21.0; +static const double c24 = 24.0; +static const double c28 = 28.0; +static const double c29 = 29.0; +static const double c36 = 36.0; +static const double c48 = 48.0; +static const double c50 = 50.0; +static const double c56 = 56.0; +static const double c152 = 152.0; +static const double c130 = 130.0; +static const double one = 1.0; +static const double two = 2.0; +static const double three = 3.0; +static const double four = 4.0; +static const double five = 5.0; +static const double six = 6.0; +static const double seven = 7.0; +static const double eight = 8.0; +static const double nine = 9.0; +static const double fourteen = 14.0; +static const double fiveteen = 15.0; +static const double sixteen = 16.0; +static const double twentyone = 21.0; +static const double twentyfour = 24.0; +static const double twentyeight = 28.0; +static const double twentynine = 29.0; +static const double fourtyeight = 48.0; +static const double fifty = 50.0; +static const double fiftysix = 56.0; -} +} // namespace UbMath #endif diff --git a/src/basics/basics/utilities/UbObservable.h b/src/basics/basics/utilities/UbObservable.h index f877718f1..0cbbe5655 100644 --- a/src/basics/basics/utilities/UbObservable.h +++ b/src/basics/basics/utilities/UbObservable.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,8 +33,8 @@ #ifndef UBOBSERVABLE_H #define UBOBSERVABLE_H -#include <list> #include <iostream> +#include <list> #include <basics/utilities/UbObserver.h> @@ -49,8 +49,8 @@ class UbObserver; //! this destructor is called AFTER the destructor of the //! child classes. if you down_cast the pointer sent with the //! objectWillBeDeleted(UbObserver* objpointer) then have to go this: -//! -//! if(dynamic_cast<UbObserver*>(observedObj)==objpointer) +//! +//! if(dynamic_cast<UbObserver*>(observedObj)==objpointer) //! (e.g.) observedObj=NULL; //! example: see end of file //! @@ -66,159 +66,149 @@ class UbObserver; //! ////////////////////////////////////////////////////////////////////////// -class UbObservable +class UbObservable { protected: - /*======================================================================*/ - /* Konstruktoren */ - /* */ - /** - Creates a UbObservable itself to be the object to be observed. - Usually this constructor is used in extended classes. - */ - UbObservable() - = default; - - UbObservable(const UbObservable& /*src*/) - { - //no copy of observers !!! - } - - //falls irgendein schlaumeier den =operator von UbObservable aufrufen sollte, - //dann macht diesr auch keine kopie! (Allg: zuweisungsoperatoren werden nie vererbt - UbObservable& operator=(const UbObservable& /*src*/) - { - return *this; - } - - // /** - // Creates a UbObservable for the specified Object to be observed. - // Usually this constructor is used in associating UbObservable. - // @param object Object to be observed - // */ + /*======================================================================*/ + /* Konstruktoren */ + /* */ + /** + Creates a UbObservable itself to be the object to be observed. + Usually this constructor is used in extended classes. + */ + UbObservable() = default; + + UbObservable(const UbObservable & /*src*/) + { + // no copy of observers !!! + } + + // falls irgendein schlaumeier den =operator von UbObservable aufrufen sollte, + // dann macht diesr auch keine kopie! (Allg: zuweisungsoperatoren werden nie vererbt + UbObservable &operator=(const UbObservable & /*src*/) { return *this; } + + // /** + // Creates a UbObservable for the specified Object to be observed. + // Usually this constructor is used in associating UbObservable. + // @param object Object to be observed + // */ public: - /*======================================================================*/ - /* Destruktor */ - /* */ - /** - */ - virtual ~UbObservable() - { - this->notifyObserversObjectWillBeDeleted(); - } + /*======================================================================*/ + /* Destruktor */ + /* */ + /** + */ + virtual ~UbObservable() { this->notifyObserversObjectWillBeDeleted(); } + + /*======================================================================*/ + /* methods */ + /* */ - /*======================================================================*/ - /* methods */ - /* */ - - /** - Adds an UbObserver to the observerlist. - @param observer the observer to add to this observable (note that an observer may observe c1 observable more than once) - */ - virtual void addObserver(UbObserver* observer) - { - if(!observer) return; - for(std::list<UbObserver*>::iterator pos=mObserverList.begin();pos!=mObserverList.end();++pos) - { - if(*pos == observer) return; - } - this->mObserverList.push_back(observer); - } - /** - Deletes an UbObserver from the observerlist. - @param observer the observer to remove from this observable (note that all observers identical are deleted) - ( delete means delete Heap... but here we're only removing a pointer) - */ - virtual void removeObserver(UbObserver* observer) - { - if(!observer) return; - this->mObserverList.remove(observer); + /** + Adds an UbObserver to the observerlist. + @param observer the observer to add to this observable (note that an observer may observe c1 observable more than + once) + */ + virtual void addObserver(UbObserver *observer) + { + if (!observer) + return; + for (std::list<UbObserver *>::iterator pos = mObserverList.begin(); pos != mObserverList.end(); ++pos) { + if (*pos == observer) + return; + } + this->mObserverList.push_back(observer); + } + /** + Deletes an UbObserver from the observerlist. + @param observer the observer to remove from this observable (note that all observers identical are deleted) + ( delete means delete Heap... but here we're only removing a pointer) + */ + virtual void removeObserver(UbObserver *observer) + { + if (!observer) + return; + this->mObserverList.remove(observer); + } + /** + Deletes all Observers from the observerlist. + ( delete means delete Heap... but here we're only removing a pointer) + */ + virtual void removeAllObservers() { this->mObserverList.clear(); } - } - /** - Deletes all Observers from the observerlist. - ( delete means delete Heap... but here we're only removing a pointer) - */ - virtual void removeAllObservers() - { - this->mObserverList.clear(); - } - - /** - Checks whether the specified UbObserver observes this observable. - @param observer the observer to remove from this observable (note that all observers identical are deleted) - @return true if the specified observer observes this observable - */ - virtual bool isObservedBy(UbObserver* observer) - { - if(!observer) return false; - for(std::list<UbObserver*>::iterator pos=mObserverList.begin();pos!=mObserverList.end();++pos) - { - if(*pos == observer) return true; - } - return false; - } - /** - Notifies all of its observers that something happened. Does nothing, if the observed object is null. - Calls the Method UbObserver.objectChanged(Object) with the object of this observable as parameter. - The Method UbObserver.objectChanged(Object) must be defined - by each class implementing the interface TiObserver - */ - virtual void notifyObserversObjectChanged() - { - std::list<UbObserver*>::iterator tmp_pos; //es kann sein, dass der aktuelle observer waehrend - //objectChanged() removed wird... - for(std::list<UbObserver*>::iterator pos=mObserverList.begin();pos!=mObserverList.end();) - { - //cout<<"in notifyObserversObjectChanged\n"; - //cout<<this->mObserverList.size()<<endl; + /** + Checks whether the specified UbObserver observes this observable. + @param observer the observer to remove from this observable (note that all observers identical are deleted) + @return true if the specified observer observes this observable + */ + virtual bool isObservedBy(UbObserver *observer) + { + if (!observer) + return false; + for (std::list<UbObserver *>::iterator pos = mObserverList.begin(); pos != mObserverList.end(); ++pos) { + if (*pos == observer) + return true; + } + return false; + } + /** + Notifies all of its observers that something happened. Does nothing, if the observed object is null. + Calls the Method UbObserver.objectChanged(Object) with the object of this observable as parameter. + The Method UbObserver.objectChanged(Object) must be defined + by each class implementing the interface TiObserver + */ + virtual void notifyObserversObjectChanged() + { + std::list<UbObserver *>::iterator tmp_pos; // es kann sein, dass der aktuelle observer waehrend + // objectChanged() removed wird... + for (std::list<UbObserver *>::iterator pos = mObserverList.begin(); pos != mObserverList.end();) { + // cout<<"in notifyObserversObjectChanged\n"; + // cout<<this->mObserverList.size()<<endl; - tmp_pos = pos++; // erst tmp_pos=pos und dann pos++ - (*tmp_pos)->objectChanged(this); - } - } + tmp_pos = pos++; // erst tmp_pos=pos und dann pos++ + (*tmp_pos)->objectChanged(this); + } + } - std::list<UbObserver*>* getObserverList() { return &mObserverList;} + std::list<UbObserver *> *getObserverList() { return &mObserverList; } - virtual std::string toString() { return "UbObservable - toString()"; } + virtual std::string toString() { return "UbObservable - toString()"; } private: - /** - Notifies all of its observers that something happened. Does nothing, if the observed object is null. - Calls the Method UbObserver.objectChanged(Object) with the object of this observable as parameter. - The Method UbObserver.objectChanged(Object) must be defined - by each class implementing the interface TiObserver - */ - virtual void notifyObserversObjectWillBeDeleted() - { - std::list<UbObserver*>::iterator tmp_pos; //es kann sein, dass der aktuelle observer waehrend - //objectWillBeDeleted() removed wird... - for(std::list<UbObserver*>::iterator pos=mObserverList.begin();pos!=mObserverList.end();) - { - //cout<<"in notifyObserversObjectWillBeDeleted\n"; - //cout<<this->mObserverList.size()<<endl; + /** + Notifies all of its observers that something happened. Does nothing, if the observed object is null. + Calls the Method UbObserver.objectChanged(Object) with the object of this observable as parameter. + The Method UbObserver.objectChanged(Object) must be defined + by each class implementing the interface TiObserver + */ + virtual void notifyObserversObjectWillBeDeleted() + { + std::list<UbObserver *>::iterator tmp_pos; // es kann sein, dass der aktuelle observer waehrend + // objectWillBeDeleted() removed wird... + for (std::list<UbObserver *>::iterator pos = mObserverList.begin(); pos != mObserverList.end();) { + // cout<<"in notifyObserversObjectWillBeDeleted\n"; + // cout<<this->mObserverList.size()<<endl; - tmp_pos = pos++; - (*tmp_pos)->objectWillBeDeleted(this); - } - } + tmp_pos = pos++; + (*tmp_pos)->objectWillBeDeleted(this); + } + } - std::list<UbObserver*> mObserverList; + std::list<UbObserver *> mObserverList; }; /*=========================================================================*/ - #ifdef RCF_USE_SF_SERIALIZATION - SF_NO_CTOR(UbObservable); -#endif //RCF_USE_SF_SERIALIZATION +SF_NO_CTOR(UbObservable); +#endif // RCF_USE_SF_SERIALIZATION #endif -//// E X A M P L E +//// E X A M P L E ////=================== -//class Point : public UbObservable +// class Point : public UbObservable //{ -//public: +// public: // Point(){x=y=0;} // ~Point(){} // void setXCorrdinates(int x,int y) @@ -226,14 +216,14 @@ private: // this->x = x; this->y = y; // this->notifyObserverObjectChanged(); // } -//private: +// private: // int x,y; //}; -//class VisPoint : public UbObserver +// class VisPoint : public UbObserver //{ -//public: +// public: // VisPoint(Point* point) -// { +// { // this->point = point; // this->point->addObserver(this); // } @@ -264,6 +254,6 @@ private: // //was hingegen immer moeglich sein sollte: // //if(dynamic_cast<void*>(objectForDeletion)==dynamic_cast<void*>(this->point)) // } -//private: +// private: // Point* point; //}; diff --git a/src/basics/basics/utilities/UbObserver.h b/src/basics/basics/utilities/UbObserver.h index dab5d28c0..ecba69207 100644 --- a/src/basics/basics/utilities/UbObserver.h +++ b/src/basics/basics/utilities/UbObserver.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -46,33 +46,29 @@ class UbObservable; //! ////////////////////////////////////////////////////////////////////////// -class UbObserver +class UbObserver { protected: - - UbObserver()= default; + UbObserver() = default; public: + virtual ~UbObserver() = default; - virtual ~UbObserver()= default; - - /*======================================================================*/ - /* Methods */ - /* */ - /*! - This function is called when the observable indicated that an object - has changed. - \param changedObject Object which has changed - */ - virtual void objectChanged(UbObservable* changedObject)=0; - /*! - This function is called when the observable indicated that an object - should be deleted. - \param objectForDeletion Object which should be deleted - */ - virtual void objectWillBeDeleted(UbObservable* objectForDeletion)=0; + /*======================================================================*/ + /* Methods */ + /* */ + /*! + This function is called when the observable indicated that an object + has changed. + \param changedObject Object which has changed + */ + virtual void objectChanged(UbObservable *changedObject) = 0; + /*! + This function is called when the observable indicated that an object + should be deleted. + \param objectForDeletion Object which should be deleted + */ + virtual void objectWillBeDeleted(UbObservable *objectForDeletion) = 0; }; #endif - - diff --git a/src/basics/basics/utilities/UbScheduler.h b/src/basics/basics/utilities/UbScheduler.h index fcb410b22..08bb38ba8 100644 --- a/src/basics/basics/utilities/UbScheduler.h +++ b/src/basics/basics/utilities/UbScheduler.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,22 +33,22 @@ #ifndef UBSCHEDULER_H #define UBSCHEDULER_H +#include <algorithm> +#include <cassert> +#include <iomanip> #include <iostream> -#include <string> #include <limits> -#include <cassert> #include <sstream> -#include <iomanip> -#include <algorithm> +#include <string> -#include <basics/utilities/UbSystem.h> -#include <basics/utilities/UbMath.h> -#include <basics/utilities/UbInfinity.h> #include <basics/utilities/UbComparators.h> +#include <basics/utilities/UbInfinity.h> +#include <basics/utilities/UbMath.h> +#include <basics/utilities/UbSystem.h> ////////////////////////////////////////////////////////////////////////// //! -//! \brief A class implements scheduling. +//! \brief A class implements scheduling. //! \details This class is not thread save. //! ////////////////////////////////////////////////////////////////////////// @@ -56,276 +56,278 @@ class UbScheduler { public: - class UbSchedule - { - friend class UbScheduler; - public: - UbSchedule() : step(Ub::inf), begin(Ub::inf), end(Ub::inf) { } - UbSchedule(const double& step, const double& begin=0.0, const double& end=Ub::inf) - : step(step), begin(begin), end(end) - { - } - double getStep() const { return this->step; } - double getBegin() const { return this->begin; } - double getEnd() const { return this->end; } - - /*==========================================================*/ - std::string toString() { std::stringstream text; text<<*this; return text.str(); } - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, const UbSchedule& schedule) - { - os<<"Schedule[start,end,step]=["<<schedule.begin<<", "<<schedule.end<<", "<<schedule.step<<"]"; - return os; - } + class UbSchedule + { + friend class UbScheduler; - private: - double step, begin, end; - }; + public: + UbSchedule() : step(Ub::inf), begin(Ub::inf), end(Ub::inf) {} + UbSchedule(const double &step, const double &begin = 0.0, const double &end = Ub::inf) + : step(step), begin(begin), end(end) + { + } + double getStep() const { return this->step; } + double getBegin() const { return this->begin; } + double getEnd() const { return this->end; } + + /*==========================================================*/ + std::string toString() + { + std::stringstream text; + text << *this; + return text.str(); + } + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, const UbSchedule &schedule) + { + os << "Schedule[start,end,step]=[" << schedule.begin << ", " << schedule.end << ", " << schedule.step + << "]"; + return os; + } + + private: + double step, begin, end; + }; public: - UbScheduler() - { - this->initVals(); - } - /*==========================================================*/ - UbScheduler(const double& step,const double& begin=0, const double& end=Ub::inf ) - { - this->initVals(); - this->addSchedule(step,begin,end); - } - /*==========================================================*/ - UbScheduler(const UbSchedule& schedule) - { - this->initVals(); - this->addSchedule(schedule); - } - /*==========================================================*/ - virtual ~UbScheduler() = default; - /*==========================================================*/ - inline void addSchedule(const UbSchedule& schedule) - { - this->addSchedule(schedule.step, schedule.begin, schedule.end); - } - /*==========================================================*/ - bool addSchedule(const double& step, const double& begin, double end) - { - if( UbMath::zero(step) || begin>end ) - { - std::cerr<<"UbScheduler::addSchedule - invalid Schedule:\n\t"<<UbSchedule(step, begin, end)<<std::endl; - return false; - } - - if( UbMath::less( end, (double)Ub::inf ) ) - { - //es kann vorkommen, dass man mit dem intervall nicht genau auf den letzten wert kommt - //(z.B. step=2; start=0; end=9; -> ende wird angepasst) - //also wenn end-begin>Ub::inf ist, dann geht es halt nicht.. ein cast in long double half hier nichts - double multiplier=0.0; - double fractpart = modf( (end-begin)/step, &multiplier); - if( !UbMath::zero(fractpart) ) - { - //tmp-speicherung (fuer cerr) - fractpart = end; - //neues ende - end = begin+multiplier*step; - - std::cerr<<"Warning: UbScheduler::addSchedule - " - <<"end of schedule was adapted to intervall \n\t" - <<"from "<< UbSchedule(step, begin, fractpart) <<" to "<< UbSchedule(step, begin, end) <<std::endl; - } - } + UbScheduler() { this->initVals(); } + /*==========================================================*/ + UbScheduler(const double &step, const double &begin = 0, const double &end = Ub::inf) + { + this->initVals(); + this->addSchedule(step, begin, end); + } + /*==========================================================*/ + UbScheduler(const UbSchedule &schedule) + { + this->initVals(); + this->addSchedule(schedule); + } + /*==========================================================*/ + virtual ~UbScheduler() = default; + /*==========================================================*/ + inline void addSchedule(const UbSchedule &schedule) + { + this->addSchedule(schedule.step, schedule.begin, schedule.end); + } + /*==========================================================*/ + bool addSchedule(const double &step, const double &begin, double end) + { + if (UbMath::zero(step) || begin > end) { + std::cerr << "UbScheduler::addSchedule - invalid Schedule:\n\t" << UbSchedule(step, begin, end) + << std::endl; + return false; + } + + if (UbMath::less(end, (double)Ub::inf)) { + // es kann vorkommen, dass man mit dem intervall nicht genau auf den letzten wert kommt + //(z.B. step=2; start=0; end=9; -> ende wird angepasst) + // also wenn end-begin>Ub::inf ist, dann geht es halt nicht.. ein cast in long double half hier nichts + double multiplier = 0.0; + double fractpart = modf((end - begin) / step, &multiplier); + if (!UbMath::zero(fractpart)) { + // tmp-speicherung (fuer cerr) + fractpart = end; + // neues ende + end = begin + multiplier * step; + + std::cerr << "Warning: UbScheduler::addSchedule - " + << "end of schedule was adapted to intervall \n\t" + << "from " << UbSchedule(step, begin, fractpart) << " to " << UbSchedule(step, begin, end) + << std::endl; + } + } + + // nu aber: + schedules.emplace_back(step, begin, end); - //nu aber: - schedules.emplace_back(step, begin, end); + if (end > maxT) + maxT = end; - if( end>maxT ) maxT = end; + double potentialDueTime; + if (calcNextDueTimeForSchedule(schedules.back(), lastUsedT, potentialDueTime) && + potentialDueTime < nextDueTime) { + nextDueTime = potentialDueTime; + } - double potentialDueTime; - if( calcNextDueTimeForSchedule(schedules.back(), lastUsedT, potentialDueTime) - && potentialDueTime < nextDueTime ) - { - nextDueTime = potentialDueTime; - } + return true; + } + /*==========================================================*/ + // returns true if scheduler contains schedules + bool hasSchedules() const { return !schedules.empty(); } + /*==========================================================*/ + // time bei dem das letzte mal isDue(time) true war + double getLastDueTime() const { return lastDueTime; } + /*==========================================================*/ + // time bei dem das naechste mal isDue(time) true ergibt + double getNextDueTime() const { return nextDueTime; } + /*==========================================================*/ + // maxDueTime (maxTime der Schedules! + double getMaxDueTime() const { return this->maxT; } + /*==========================================================*/ + bool isDue(const double &t) + { + lastUsedT = t; + if (UbMath::greaterEqual(t, nextDueTime)) { + // groesser maxT is nicht + if (UbMath::greater(t, maxT)) + return false; - return true; - } - /*==========================================================*/ - //returns true if scheduler contains schedules - bool hasSchedules() const { return !schedules.empty(); } - /*==========================================================*/ - //time bei dem das letzte mal isDue(time) true war - double getLastDueTime() const { return lastDueTime; } - /*==========================================================*/ - //time bei dem das naechste mal isDue(time) true ergibt - double getNextDueTime() const { return nextDueTime; } - /*==========================================================*/ - //maxDueTime (maxTime der Schedules! - double getMaxDueTime() const { return this->maxT; } - /*==========================================================*/ - bool isDue(const double& t) - { - lastUsedT = t; - if( UbMath::greaterEqual(t,nextDueTime) ) - { - //groesser maxT is nicht - if( UbMath::greater(t,maxT) ) return false; - - //temp var - double actDueTime = nextDueTime; + // temp var + double actDueTime = nextDueTime; - //um Suche nach nextDueTime bei "Zukunfts-t" zu optimieren, setzt man die "start"-suchzeit auf "t-1": - nextDueTime = t-1; //t-1 deshlab, damit falls z.B. while Schleife nicht durchlaufen wird - //die folgende if Abfrage nicht faelschlicher Weise true ist! - while( UbMath::greaterEqual(t,nextDueTime) && !UbMath::equal(nextDueTime, maxT) ) - { - double tmpNextDueTime = maxT, potentialDueTime=-1.0; - for(std::size_t i=0; i<schedules.size(); i++) - { - if( calcNextDueTimeForSchedule(schedules[i], nextDueTime, potentialDueTime) - && potentialDueTime < tmpNextDueTime ) - { - assert( nextDueTime < potentialDueTime ); - tmpNextDueTime = potentialDueTime; - } + // um Suche nach nextDueTime bei "Zukunfts-t" zu optimieren, setzt man die "start"-suchzeit auf "t-1": + nextDueTime = t - 1; // t-1 deshlab, damit falls z.B. while Schleife nicht durchlaufen wird + // die folgende if Abfrage nicht faelschlicher Weise true ist! + while (UbMath::greaterEqual(t, nextDueTime) && !UbMath::equal(nextDueTime, maxT)) { + double tmpNextDueTime = maxT, potentialDueTime = -1.0; + for (std::size_t i = 0; i < schedules.size(); i++) { + if (calcNextDueTimeForSchedule(schedules[i], nextDueTime, potentialDueTime) && + potentialDueTime < tmpNextDueTime) { + assert(nextDueTime < potentialDueTime); + tmpNextDueTime = potentialDueTime; + } + } + actDueTime = nextDueTime; + nextDueTime = tmpNextDueTime; } - actDueTime = nextDueTime; - nextDueTime = tmpNextDueTime; - } - //wenn t = der aktuuellen oder gar schon der naechstmoeglichen ist (hierbei wurde - //zuvor actDueTime und nextDueTime ggf. angepasst) - //Bsp.: nextDuTime war 5, aber fuer t=400 gilt andere schedule -> Bsp actDue=350 und nextDue 405 - if( UbMath::equal(t,actDueTime) - || UbMath::equal(t,nextDueTime) ) - { - lastDueTime = t; - return true; - } - } - else if( UbMath::lessEqual(t, lastDueTime) ) - { - if(UbMath::equal(t, lastDueTime) ) return true; //braucht man, wenn man fuer dasselbe t isDue(t) aufruft - else - { - //Fall: Zeit liegt faktisch in der Vergangenheit -> neu initialsisieren - double tmpNextDueTime = maxT, potentialDueTime=-1.0; - for(size_t i=0; i<schedules.size(); i++) - { - if( calcNextDueTimeForSchedule(schedules[i], t-1, potentialDueTime) - && potentialDueTime < tmpNextDueTime ) - { - tmpNextDueTime = potentialDueTime; - } + // wenn t = der aktuuellen oder gar schon der naechstmoeglichen ist (hierbei wurde + // zuvor actDueTime und nextDueTime ggf. angepasst) + // Bsp.: nextDuTime war 5, aber fuer t=400 gilt andere schedule -> Bsp actDue=350 und nextDue 405 + if (UbMath::equal(t, actDueTime) || UbMath::equal(t, nextDueTime)) { + lastDueTime = t; + return true; } - nextDueTime = tmpNextDueTime; + } else if (UbMath::lessEqual(t, lastDueTime)) { + if (UbMath::equal(t, lastDueTime)) + return true; // braucht man, wenn man fuer dasselbe t isDue(t) aufruft + else { + // Fall: Zeit liegt faktisch in der Vergangenheit -> neu initialsisieren + double tmpNextDueTime = maxT, potentialDueTime = -1.0; + for (size_t i = 0; i < schedules.size(); i++) { + if (calcNextDueTimeForSchedule(schedules[i], t - 1, potentialDueTime) && + potentialDueTime < tmpNextDueTime) { + tmpNextDueTime = potentialDueTime; + } + } + nextDueTime = tmpNextDueTime; - return UbMath::equal(t, nextDueTime); - } - } + return UbMath::equal(t, nextDueTime); + } + } - return false; - } - /*==========================================================*/ - inline double getMinBegin( ) const - { - if( schedules.empty() ) return Ub::inf; - return std::min_element(schedules.begin(), schedules.end(),UbComparators::membercomp(&UbSchedule::getBegin) )->getBegin(); - } - /*==========================================================*/ - inline double getMaxBegin( ) const - { - if( schedules.empty() ) return Ub::inf; - return std::max_element(schedules.begin(), schedules.end(),UbComparators::membercomp(&UbSchedule::getBegin) )->getBegin(); - } - /*==========================================================*/ - inline double getMinEnd( ) const - { - if( schedules.empty() ) return Ub::inf; - return std::min_element(schedules.begin(), schedules.end(),UbComparators::membercomp(&UbSchedule::getEnd) )->getEnd(); - } - /*==========================================================*/ - inline double getMaxEnd( ) const - { - if( schedules.empty() ) return Ub::inf; - return std::max_element(schedules.begin(), schedules.end(),UbComparators::membercomp(&UbSchedule::getEnd) )->getEnd(); - } - /*==========================================================*/ - inline double getMinStep( ) const - { - if( schedules.empty() ) return Ub::inf; - return std::min_element(schedules.begin(), schedules.end(),UbComparators::membercomp(&UbSchedule::getStep) )->getStep(); - } - /*==========================================================*/ - inline double getMaxStep( ) const - { - if( schedules.empty() ) return Ub::inf; - return std::max_element(schedules.begin(), schedules.end(),UbComparators::membercomp(&UbSchedule::getStep) )->getStep(); - } - /*==========================================================*/ - inline std::string toString() const - { - std::stringstream text; - text<<*this; - return text.str(); - } - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, const UbScheduler& scheduler) - { - os<<"UbScheduler\n"; - os<<"Schedule | start | end | intervall "<<std::endl; - for(std::size_t i=0; i<scheduler.schedules.size(); i++) - os<<std::setw(9)<<i<<"|" - <<std::setw(19)<<scheduler.schedules[i].getBegin()<<"|" - <<std::setw(19)<<scheduler.schedules[i].getEnd() <<"|" - <<std::setw(19)<<scheduler.schedules[i].getStep() <<std::endl; - return os; - } + return false; + } + /*==========================================================*/ + inline double getMinBegin() const + { + if (schedules.empty()) + return Ub::inf; + return std::min_element(schedules.begin(), schedules.end(), UbComparators::membercomp(&UbSchedule::getBegin)) + ->getBegin(); + } + /*==========================================================*/ + inline double getMaxBegin() const + { + if (schedules.empty()) + return Ub::inf; + return std::max_element(schedules.begin(), schedules.end(), UbComparators::membercomp(&UbSchedule::getBegin)) + ->getBegin(); + } + /*==========================================================*/ + inline double getMinEnd() const + { + if (schedules.empty()) + return Ub::inf; + return std::min_element(schedules.begin(), schedules.end(), UbComparators::membercomp(&UbSchedule::getEnd)) + ->getEnd(); + } + /*==========================================================*/ + inline double getMaxEnd() const + { + if (schedules.empty()) + return Ub::inf; + return std::max_element(schedules.begin(), schedules.end(), UbComparators::membercomp(&UbSchedule::getEnd)) + ->getEnd(); + } + /*==========================================================*/ + inline double getMinStep() const + { + if (schedules.empty()) + return Ub::inf; + return std::min_element(schedules.begin(), schedules.end(), UbComparators::membercomp(&UbSchedule::getStep)) + ->getStep(); + } + /*==========================================================*/ + inline double getMaxStep() const + { + if (schedules.empty()) + return Ub::inf; + return std::max_element(schedules.begin(), schedules.end(), UbComparators::membercomp(&UbSchedule::getStep)) + ->getStep(); + } + /*==========================================================*/ + inline std::string toString() const + { + std::stringstream text; + text << *this; + return text.str(); + } + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, const UbScheduler &scheduler) + { + os << "UbScheduler\n"; + os << "Schedule | start | end | intervall " << std::endl; + for (std::size_t i = 0; i < scheduler.schedules.size(); i++) + os << std::setw(9) << i << "|" << std::setw(19) << scheduler.schedules[i].getBegin() << "|" << std::setw(19) + << scheduler.schedules[i].getEnd() << "|" << std::setw(19) << scheduler.schedules[i].getStep() + << std::endl; + return os; + } protected: - /*==========================================================*/ - void initVals() - { - lastUsedT = -Ub::inf; - lastDueTime = -Ub::inf; - nextDueTime = Ub::inf; - maxT = -Ub::inf; - } - /*==========================================================*/ - // calculates next due time for a schedule - // with nextDueTime > searchStart - bool calcNextDueTimeForSchedule(const UbSchedule& schedule, const double& searchStart, double& nextDueTime ) - { - if ( UbMath::greater(searchStart, schedule.end ) ) return false; - else if( UbMath::less( searchStart, schedule.begin) ) nextDueTime = schedule.begin; - else - { - nextDueTime = schedule.begin + ((int)((searchStart-schedule.begin)/schedule.step)+1)*schedule.step; - if( UbMath::less( nextDueTime, searchStart ) - || UbMath::greater(nextDueTime, schedule.end) ) - { + /*==========================================================*/ + void initVals() + { + lastUsedT = -Ub::inf; + lastDueTime = -Ub::inf; + nextDueTime = Ub::inf; + maxT = -Ub::inf; + } + /*==========================================================*/ + // calculates next due time for a schedule + // with nextDueTime > searchStart + bool calcNextDueTimeForSchedule(const UbSchedule &schedule, const double &searchStart, double &nextDueTime) + { + if (UbMath::greater(searchStart, schedule.end)) return false; - } - } - return true; - } + else if (UbMath::less(searchStart, schedule.begin)) + nextDueTime = schedule.begin; + else { + nextDueTime = schedule.begin + ((int)((searchStart - schedule.begin) / schedule.step) + 1) * schedule.step; + if (UbMath::less(nextDueTime, searchStart) || UbMath::greater(nextDueTime, schedule.end)) { + return false; + } + } + return true; + } protected: - double lastUsedT; - double lastDueTime; - double nextDueTime; - double maxT; - - std::vector<UbSchedule> schedules; + double lastUsedT; + double lastDueTime; + double nextDueTime; + double maxT; + + std::vector<UbSchedule> schedules; }; using UbSchedule = UbScheduler::UbSchedule; -#endif //UBSCHEDULER_H +#endif // UBSCHEDULER_H - - -//int main(int argc, char** argv) -//{ +// int main(int argc, char** argv) +//{ // UbScheduler writeSchedule; //// writeSchedule.addSchedule(0,2000,100); //// writeSchedule.addSchedule(3005,4500,300); @@ -343,4 +345,3 @@ using UbSchedule = UbScheduler::UbSchedule; // } // return 0; //} - diff --git a/src/basics/basics/utilities/UbSystem.h b/src/basics/basics/utilities/UbSystem.h index 975e70275..8e676811a 100644 --- a/src/basics/basics/utilities/UbSystem.h +++ b/src/basics/basics/utilities/UbSystem.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,60 +34,59 @@ #define UBSYSTEM_H #if defined(_WIN32) || defined(_WIN64) - #define UBSYSTEM_WINDOWS - #include <process.h> - #include <io.h> - #include <direct.h> - //#ifndef _WINSOCK2API_ //ansonsten gibt es mecker bei #include "Windows.h" und ::Sleep() - // #define _WINSOCK2API_ - // #include<WinSock2.h> - //#endif - #include <windows.h> - //#include <Windows.h> - //#include <tchar.h> +#define UBSYSTEM_WINDOWS +#include <direct.h> +#include <io.h> +#include <process.h> +//#ifndef _WINSOCK2API_ //ansonsten gibt es mecker bei #include "Windows.h" und ::Sleep() +// #define _WINSOCK2API_ +// #include<WinSock2.h> +//#endif +#include <windows.h> +//#include <Windows.h> +//#include <tchar.h> #elif defined(__APPLE__) - #define UBSYSTEM_APPLE - #include "dirent.h" - #include "sys/stat.h" - #include <sys/syscall.h> - #include <sys/stat.h> - #include <unistd.h> +#define UBSYSTEM_APPLE +#include "dirent.h" +#include "sys/stat.h" +#include <sys/stat.h> +#include <sys/syscall.h> +#include <unistd.h> #elif (defined(__amd64) || defined(__amd64__) || defined(__unix__)) && !defined(__AIX__) - #define UBSYSTEM_LINUX - #include "dirent.h" - #include <sys/stat.h> - #include <unistd.h> - #include <cstring> +#define UBSYSTEM_LINUX +#include "dirent.h" +#include <cstring> +#include <sys/stat.h> +#include <unistd.h> #elif defined(__AIX__) - #define UBSYSTEM_AIX - #include "dirent.h" - #include <unistd.h> - #include <sys/stat.h> - #include <sys/types.h> +#define UBSYSTEM_AIX +#include "dirent.h" +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> #else - #error "UbSystem::UnknownMachine" +#error "UbSystem::UnknownMachine" #endif #if defined(__unix__) && defined(__CYGWIN__) - #define UBSYSTEM_CYGWIN - #include <windows.h> +#define UBSYSTEM_CYGWIN +#include <windows.h> #elif defined(__unix__) - #include <sys/syscall.h> +#include <sys/syscall.h> #endif -#if defined(min) || defined(max) //daruch kann man sich spaeter #undef min; #undef max erparen -# error add NOMINMAX to preprocessor defines +#if defined(min) || defined(max) // daruch kann man sich spaeter #undef min; #undef max erparen +#error add NOMINMAX to preprocessor defines #endif - -#include <iostream> -#include <iomanip> -#include <string> -#include <sstream> #include <algorithm> -#include <typeinfo> #include <cctype> //for toupper #include <ctime> +#include <iomanip> +#include <iostream> +#include <sstream> +#include <string> +#include <typeinfo> #include <basics/utilities/UbException.h> #include <basics/utilities/UbLogger.h> @@ -96,475 +95,463 @@ #include <boost/thread.hpp> #endif // CAB_BOOST -//DEFINE TO STRING -//e.g. #define FOO hallo +// DEFINE TO STRING +// e.g. #define FOO hallo // -> QUOTEME(FOO) == "hallo" #define _QUOTEME(x) #x #define QUOTEME(x) _QUOTEME(x) -//allg.: -//const int * C1 -> C1 is variable pointer to a constant integer -//int const * C2 -> C2 is variable pointer to a constant integer (same as above) -//int * const C3 -> C3 is constant pointer to a variable integer -//int const * const C4 -> C4 is constant pointer to a constant integer +// allg.: +// const int * C1 -> C1 is variable pointer to a constant integer +// int const * C2 -> C2 is variable pointer to a constant integer (same as above) +// int * const C3 -> C3 is constant pointer to a variable integer +// int const * const C4 -> C4 is constant pointer to a constant integer ////////////////////////////////////////////////////////////////////////// -//UbSystem +// UbSystem ////////////////////////////////////////////////////////////////////////// namespace UbSystem { - template<bool> struct ub_static_assert; //deklaration (ub_xxx da static_assert in C++0x ein keyword werden wird) - template<> struct ub_static_assert<true>{}; //deklaration + definition der spezialisierung fuer "true" - //ub_static_assert<false> fuehrt zu compiler fehler, da dafuer - //keine implementierung vorhanden! //UB_STATIC_ASSERT(false) - - /*==========================================================*/ - inline void sleepMs(const unsigned int& msec) - { - #if defined(UBSYSTEM_WINDOWS) - ::Sleep( (msec==0) ? 1 : msec ); // +1 here causes a context switch if SleepMSec(0) is called - #elif (defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)) && !defined(UBSYSTEM_CYGWIN) - ::usleep(1000*msec); - #elif defined(UBSYSTEM_CYGWIN) - ::Sleep( (msec==0) ? 1 : msec ); - #else - #error "UbSystem::sleepMSec - UnknownMachine" - #endif - } - /*==========================================================*/ - inline void sleepS(const unsigned int& sec) - { - #if defined(UBSYSTEM_WINDOWS) || defined(UBSYSTEM_CYGWIN) - ::Sleep( (sec==0) ? 1 : sec*1000 ); // +1 here causes a context switch if sleepS(0) is called - #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) && !defined(UBSYSTEM_CYGWIN) - ::sleep(sec); - #else - #error "UbSystem::sleepS - UnknownMachine" - #endif - } - /*==========================================================*/ - //checks if the bits of bitmask are set in value - template<typename T> - inline bool bitCheck(const T& value, const T& bitmask) - { - return ( (value & bitmask) == bitmask); - } - /*==========================================================*/ - //checks if the bits of bitmask are set in value - template<typename T> - inline void setBit(T& value, const T& bitmask) - { - value |= bitmask; - } - /*==========================================================*/ - template<typename T> - inline void unsetBit(T& value, const T& bitmask) - { - value &= ~bitmask; - } - /*==========================================================*/ - //returns bitmask as string e.g. 0001 0100 1101 - template<typename T> - inline std::string getBitString(const T& value) - { - std::stringstream text; - for(int i=sizeof(value)*8-1/*8 bits per byte*/; i>=0; i--) - { - text<<(char) ( ((value>>i) & 1) + '0'); - if(i%4 == 0 && i>0) text<<' '; - } - return text.str(); - } - /*==========================================================*/ - //converts string to type T - // usage: int x = stringTo<int>("123"); - template<typename T> - inline T stringTo(const std::string& s) - { - std::istringstream iss(s); - T x; - iss >> x; - if(!iss) - UB_THROW( UbException(UB_EXARGS," cannot convert \""+s+"\" to type <"+static_cast<std::string>(typeid(x).name())+">") ); - - return x; - } - /*==========================================================*/ - // usage: string s = toString(x); - template<typename T> - inline std::string toString(const T& x, int precision=15) - { - std::ostringstream oss; - oss<<std::setprecision(precision); - oss<<x; - return oss.str(); - } - /*==========================================================*/ - //e.g. str="iHcsnW" -> "IHCSNW" - inline std::string toUpperString(const std::string& str) - { - std::string tmp(str); - std::transform(tmp.begin(),tmp.end(),tmp.begin(), static_cast<int (*)(int)>(std::toupper)); - - return tmp; - } - /*==========================================================*/ - //e.g. str="iHcsnW" -> "ihcsnw" - inline std::string toLowerString(const std::string& str) - { - std::string tmp(str); - std::transform(tmp.begin(),tmp.end(),tmp.begin(), static_cast<int (*)(int)>(std::tolower)); - - return tmp; - } - /*==========================================================*/ - // usage: std::string s = replaceInString(str,"\\","/"); - // std::string s = replaceInString(str,"ich","du"); - static std::string replaceInString(std::string original, const std::string& replace, const std::string& replaceWith ) - { - size_t pos=0; - while( (pos=original.find(replace,pos))!=std::string::npos ) - { - original.replace(pos,replace.size(),replaceWith); - pos+=replaceWith.size(); - } - return original; - } - /*==========================================================*/ - //returns content of an enviroment variable - inline std::string getEnv(const std::string& var) - { - char* str = getenv( var.c_str()); - if( str == NULL ) - { - return std::string(""); - } - - return static_cast<std::string>( str ); - } - /*==========================================================*/ - inline bool isDirectory(const std::string& dir, const unsigned& /*attemptions*/ = 3) - { - if( dir.empty() ) - UB_THROW( UbException(UB_EXARGS,"dir is empty") ); - - std::string path = UbSystem::replaceInString(dir,"\\","/"); - - #if defined UBSYSTEM_WINDOWS - #ifndef _UNICODE - if( _access(path.c_str(), 0 ) == -1 ) return false; - #else - if( _waccess(path.c_str(), 0 ) == -1 ) return false; - #endif - #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) - struct stat stFileInfo; - if( stat(path.c_str(),&stFileInfo) != 0) - { - return false; - } - #endif - - return true; - } - /*==========================================================*/ - // usage: makeDirectory("c:/temp"); - // makeDirectory("c:/temp/"); - // return: true -> successful - // false -> failed - #if defined(CAB_BOOST) - static boost::mutex mtx_makeDirectory; - #endif - inline bool makeDirectory(const std::string& dir, const unsigned& attemptions = 3) - { - UBLOG(logDEBUG5,"UbSystem::makeDirectory - start, dir="<<dir<<" #attemptions="<<attemptions); - - if( dir.empty() ) UB_THROW( UbException(UB_EXARGS,"dir is empty") ); - std::string path = UbSystem::replaceInString(dir,"\\","/"); - - bool dirCreated = true; - #if defined UBSYSTEM_WINDOWS - if(path[path.size()-1] != '/') path+="/"; - size_t pos = 0; - while( ( pos=path.find("/",pos+1) ) != std::string::npos ) - { - std::string tmpdir = path.substr(0,pos); - #if defined(CAB_BOOST) - boost::mutex::scoped_lock lock(mtx_makeDirectory); - #endif - if( - #ifndef _UNICODE - _access(tmpdir.c_str(), 0 ) == -1 && _mkdir(tmpdir.c_str() ) == -1 - #else - _waccess(tmpdir.c_str(), 0) == -1 && _wmkdir(tmpdir.c_str()) == -1 - #endif - ) - { - UBLOG(logDEBUG5,"UbSystem::makeDirectory- dir=\""<<tmpdir<<"\" doesn't exit or makedir failed"); - dirCreated = false; - break; - } - } - #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) - std::string command = "mkdir -p \""+path+"\""; - { - #if defined(CAB_BOOST) - boost::mutex::scoped_lock lock(mtx_makeDirectory); - #endif - if(system(command.c_str())!=0) - { - UBLOG(logDEBUG5,"UbSystem::makeDirectory- dir=\""<<path<<"\" doesn't exit or makedir failed"); - dirCreated = false; - } - } - #else - #error "UbSystem::makeDirectory - UnknownMachine" - #endif - - if(!dirCreated && attemptions > 1) - { - UBLOG(logDEBUG5,"UbSystem::makeDirectory - internal call of UbSystem::makeDirectory"); - UbSystem::sleepMs(500); - dirCreated = UbSystem::makeDirectory(path, attemptions-1); - } - - UBLOG(logDEBUG5,"UbSystem::makeDirectory - end (success="<<dirCreated<<", attemptions = "<<attemptions<<")"); - return dirCreated; - } - /*==========================================================*/ -#if defined(CAB_BOOST) - static boost::mutex mtx_removeDirectory; +template <bool> +struct ub_static_assert; // deklaration (ub_xxx da static_assert in C++0x ein keyword werden wird) +template <> +struct ub_static_assert<true> { +}; // deklaration + definition der spezialisierung fuer "true" + // ub_static_assert<false> fuehrt zu compiler fehler, da dafuer + // keine implementierung vorhanden! //UB_STATIC_ASSERT(false) + +/*==========================================================*/ +inline void sleepMs(const unsigned int &msec) +{ +#if defined(UBSYSTEM_WINDOWS) + ::Sleep((msec == 0) ? 1 : msec); // +1 here causes a context switch if SleepMSec(0) is called +#elif (defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)) && !defined(UBSYSTEM_CYGWIN) + ::usleep(1000 * msec); +#elif defined(UBSYSTEM_CYGWIN) + ::Sleep((msec == 0) ? 1 : msec); +#else +#error "UbSystem::sleepMSec - UnknownMachine" +#endif +} +/*==========================================================*/ +inline void sleepS(const unsigned int &sec) +{ +#if defined(UBSYSTEM_WINDOWS) || defined(UBSYSTEM_CYGWIN) + ::Sleep((sec == 0) ? 1 : sec * 1000); // +1 here causes a context switch if sleepS(0) is called +#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) && !defined(UBSYSTEM_CYGWIN) + ::sleep(sec); +#else +#error "UbSystem::sleepS - UnknownMachine" +#endif +} +/*==========================================================*/ +// checks if the bits of bitmask are set in value +template <typename T> +inline bool bitCheck(const T &value, const T &bitmask) +{ + return ((value & bitmask) == bitmask); +} +/*==========================================================*/ +// checks if the bits of bitmask are set in value +template <typename T> +inline void setBit(T &value, const T &bitmask) +{ + value |= bitmask; +} +/*==========================================================*/ +template <typename T> +inline void unsetBit(T &value, const T &bitmask) +{ + value &= ~bitmask; +} +/*==========================================================*/ +// returns bitmask as string e.g. 0001 0100 1101 +template <typename T> +inline std::string getBitString(const T &value) +{ + std::stringstream text; + for (int i = sizeof(value) * 8 - 1 /*8 bits per byte*/; i >= 0; i--) { + text << (char)(((value >> i) & 1) + '0'); + if (i % 4 == 0 && i > 0) + text << ' '; + } + return text.str(); +} +/*==========================================================*/ +// converts string to type T +// usage: int x = stringTo<int>("123"); +template <typename T> +inline T stringTo(const std::string &s) +{ + std::istringstream iss(s); + T x; + iss >> x; + if (!iss) + UB_THROW(UbException(UB_EXARGS, " cannot convert \"" + s + "\" to type <" + + static_cast<std::string>(typeid(x).name()) + ">")); + + return x; +} +/*==========================================================*/ +// usage: string s = toString(x); +template <typename T> +inline std::string toString(const T &x, int precision = 15) +{ + std::ostringstream oss; + oss << std::setprecision(precision); + oss << x; + return oss.str(); +} +/*==========================================================*/ +// e.g. str="iHcsnW" -> "IHCSNW" +inline std::string toUpperString(const std::string &str) +{ + std::string tmp(str); + std::transform(tmp.begin(), tmp.end(), tmp.begin(), static_cast<int (*)(int)>(std::toupper)); + + return tmp; +} +/*==========================================================*/ +// e.g. str="iHcsnW" -> "ihcsnw" +inline std::string toLowerString(const std::string &str) +{ + std::string tmp(str); + std::transform(tmp.begin(), tmp.end(), tmp.begin(), static_cast<int (*)(int)>(std::tolower)); + + return tmp; +} +/*==========================================================*/ +// usage: std::string s = replaceInString(str,"\\","/"); +// std::string s = replaceInString(str,"ich","du"); +static std::string replaceInString(std::string original, const std::string &replace, const std::string &replaceWith) +{ + size_t pos = 0; + while ((pos = original.find(replace, pos)) != std::string::npos) { + original.replace(pos, replace.size(), replaceWith); + pos += replaceWith.size(); + } + return original; +} +/*==========================================================*/ +// returns content of an enviroment variable +inline std::string getEnv(const std::string &var) +{ + char *str = getenv(var.c_str()); + if (str == NULL) { + return std::string(""); + } + + return static_cast<std::string>(str); +} +/*==========================================================*/ +inline bool isDirectory(const std::string &dir, const unsigned & /*attemptions*/ = 3) +{ + if (dir.empty()) + UB_THROW(UbException(UB_EXARGS, "dir is empty")); + + std::string path = UbSystem::replaceInString(dir, "\\", "/"); + +#if defined UBSYSTEM_WINDOWS +#ifndef _UNICODE + if (_access(path.c_str(), 0) == -1) + return false; +#else + if (_waccess(path.c_str(), 0) == -1) + return false; +#endif +#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) + struct stat stFileInfo; + if (stat(path.c_str(), &stFileInfo) != 0) { + return false; + } #endif - inline int removeDirectory(const std::string& dir) - { - #if defined(CAB_BOOST) - boost::mutex::scoped_lock lock(mtx_removeDirectory); - #endif - std::string command = "rmdir \""+dir+"\""; - return std::system(command.c_str()); - } - /*==========================================================*/ - // usage : getPathFromString("c:/temp/foo.txt"); - //returns: "c:/temp" - // usage : getPathFromString("c:\\temp\\foo.txt"); - //returns: "c:/temp" - // usage : getPathFromString("foo.txt"); - // returns: "" - inline std::string getPathFromString(const std::string& fileStringWithPath) - { - std::string tmp = UbSystem::replaceInString(fileStringWithPath,"\\","/"); - std::size_t last = tmp.rfind("/"); - if(last!=std::string::npos) tmp.resize(last); - else tmp = ""; - return tmp; - } - /*==========================================================*/ - // usage : getFilenameFromString("c:/temp/foo.txt"); - // returns: "foo.txt" - // usage : getFilenameFromString("c:/temp/foo.txt",false); - // returns: "foo" - // usage : getFilenameFromString("c:/temp/"); - // returns: "" - inline std::string getFilenameFromString(const std::string& fileStringWithPath, bool withExtension = true) - { - std::string tmp = UbSystem::replaceInString(fileStringWithPath,"\\","/"); - - //remove path - std::size_t last = tmp.rfind("/"); - if(last!=std::string::npos && (last+1)<tmp.size()) tmp.erase(0,last+1); - - //remove extension - if(!withExtension) - { - last = tmp.rfind("."); - if(last!=std::string::npos) tmp.erase(last); - } - - return tmp; - } - /*==========================================================*/ - inline int getProcessID() - { - #if defined UBSYSTEM_WINDOWS - return _getpid(); - #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) - return getpid(); - #else - #error "int UbSystem::getProcessID() - UnknownMachine" - #endif - } - /*==========================================================*/ - inline unsigned long getCurrentThreadID() - { - #if defined UBSYSTEM_WINDOWS || defined(UBSYSTEM_CYGWIN) - return (unsigned long)GetCurrentThreadId(); - #elif defined(UBSYSTEM_APPLE) - uint64_t tid; - pthread_threadid_np(nullptr, &tid); - return (unsigned long)tid; - #elif defined(UBSYSTEM_LINUX) - return (unsigned long)syscall(SYS_gettid); - #elif defined(UBSYSTEM_AIX) - return (unsigned long) getpid(); //WORKAROUND for IBM (for get thread id is another function necessary) - #else - #error "unsigned long UbSystem::getCurrentThreadID() - UnknownMachine" - #endif - } - /*==========================================================*/ - inline bool isBigEndian() - { - short word = 0x4321; - if((*(char*)& word) != 0x21 ) return true; - else return false; - } - /*==========================================================*/ - inline bool isLittleEndian() - { - return !isBigEndian(); - } - /*==========================================================*/ - inline std::string getTimeStamp() - { - time_t t = time(NULL); - tm* localTime = localtime(&t); - - std::stringstream tmp; - tmp.fill('0'); - - tmp << localTime->tm_year+1900 - << "." << std::setw(2) <<localTime->tm_mon+1 - << "." << std::setw(2) << localTime->tm_mday - << "@" << std::setw(2) << localTime->tm_hour - << "." << std::setw(2) << localTime->tm_min - << "." << std::setw(2) << localTime->tm_sec ; - - return tmp.str(); - } - /*==========================================================*/ - //swap Byte Order - //usage: int test = 8; - // swapByteOrder((unsigned char*)& test, sizeof(int)) - //#define ByteSwap5(x) ByteSwap((unsigned char *) &x,sizeof(x)) - inline void swapByteOrder(unsigned char* toSwap, int length) - { - int i = 0; - int j = length-1; - while(i<j) - { - std::swap(toSwap[i], toSwap[j]); - i++, j--; - } - } - ////////////////////////////////////////////////////////////////////////// - //get host name - inline std::string getMachineName() - { - char Name[150]; + + return true; +} +/*==========================================================*/ +// usage: makeDirectory("c:/temp"); +// makeDirectory("c:/temp/"); +// return: true -> successful +// false -> failed +#if defined(CAB_BOOST) +static boost::mutex mtx_makeDirectory; +#endif +inline bool makeDirectory(const std::string &dir, const unsigned &attemptions = 3) +{ + UBLOG(logDEBUG5, "UbSystem::makeDirectory - start, dir=" << dir << " #attemptions=" << attemptions); + + if (dir.empty()) + UB_THROW(UbException(UB_EXARGS, "dir is empty")); + std::string path = UbSystem::replaceInString(dir, "\\", "/"); + + bool dirCreated = true; +#if defined UBSYSTEM_WINDOWS + if (path[path.size() - 1] != '/') + path += "/"; + size_t pos = 0; + while ((pos = path.find("/", pos + 1)) != std::string::npos) { + std::string tmpdir = path.substr(0, pos); +#if defined(CAB_BOOST) + boost::mutex::scoped_lock lock(mtx_makeDirectory); +#endif + if ( +#ifndef _UNICODE + _access(tmpdir.c_str(), 0) == -1 && _mkdir(tmpdir.c_str()) == -1 +#else + _waccess(tmpdir.c_str(), 0) == -1 && _wmkdir(tmpdir.c_str()) == -1 +#endif + ) { + UBLOG(logDEBUG5, "UbSystem::makeDirectory- dir=\"" << tmpdir << "\" doesn't exit or makedir failed"); + dirCreated = false; + break; + } + } +#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) + std::string command = "mkdir -p \"" + path + "\""; + { +#if defined(CAB_BOOST) + boost::mutex::scoped_lock lock(mtx_makeDirectory); +#endif + if (system(command.c_str()) != 0) { + UBLOG(logDEBUG5, "UbSystem::makeDirectory- dir=\"" << path << "\" doesn't exit or makedir failed"); + dirCreated = false; + } + } +#else +#error "UbSystem::makeDirectory - UnknownMachine" +#endif + + if (!dirCreated && attemptions > 1) { + UBLOG(logDEBUG5, "UbSystem::makeDirectory - internal call of UbSystem::makeDirectory"); + UbSystem::sleepMs(500); + dirCreated = UbSystem::makeDirectory(path, attemptions - 1); + } + + UBLOG(logDEBUG5, + "UbSystem::makeDirectory - end (success=" << dirCreated << ", attemptions = " << attemptions << ")"); + return dirCreated; +} +/*==========================================================*/ +#if defined(CAB_BOOST) +static boost::mutex mtx_removeDirectory; +#endif +inline int removeDirectory(const std::string &dir) +{ +#if defined(CAB_BOOST) + boost::mutex::scoped_lock lock(mtx_removeDirectory); +#endif + std::string command = "rmdir \"" + dir + "\""; + return std::system(command.c_str()); +} +/*==========================================================*/ +// usage : getPathFromString("c:/temp/foo.txt"); +// returns: "c:/temp" +// usage : getPathFromString("c:\\temp\\foo.txt"); +// returns: "c:/temp" +// usage : getPathFromString("foo.txt"); +// returns: "" +inline std::string getPathFromString(const std::string &fileStringWithPath) +{ + std::string tmp = UbSystem::replaceInString(fileStringWithPath, "\\", "/"); + std::size_t last = tmp.rfind("/"); + if (last != std::string::npos) + tmp.resize(last); + else + tmp = ""; + return tmp; +} +/*==========================================================*/ +// usage : getFilenameFromString("c:/temp/foo.txt"); +// returns: "foo.txt" +// usage : getFilenameFromString("c:/temp/foo.txt",false); +// returns: "foo" +// usage : getFilenameFromString("c:/temp/"); +// returns: "" +inline std::string getFilenameFromString(const std::string &fileStringWithPath, bool withExtension = true) +{ + std::string tmp = UbSystem::replaceInString(fileStringWithPath, "\\", "/"); + + // remove path + std::size_t last = tmp.rfind("/"); + if (last != std::string::npos && (last + 1) < tmp.size()) + tmp.erase(0, last + 1); + + // remove extension + if (!withExtension) { + last = tmp.rfind("."); + if (last != std::string::npos) + tmp.erase(last); + } + + return tmp; +} +/*==========================================================*/ +inline int getProcessID() +{ +#if defined UBSYSTEM_WINDOWS + return _getpid(); +#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX) + return getpid(); +#else +#error "int UbSystem::getProcessID() - UnknownMachine" +#endif +} +/*==========================================================*/ +inline unsigned long getCurrentThreadID() +{ +#if defined UBSYSTEM_WINDOWS || defined(UBSYSTEM_CYGWIN) + return (unsigned long)GetCurrentThreadId(); +#elif defined(UBSYSTEM_APPLE) + uint64_t tid; + pthread_threadid_np(nullptr, &tid); + return (unsigned long)tid; +#elif defined(UBSYSTEM_LINUX) + return (unsigned long)syscall(SYS_gettid); +#elif defined(UBSYSTEM_AIX) + return (unsigned long)getpid(); // WORKAROUND for IBM (for get thread id is another function necessary) +#else +#error "unsigned long UbSystem::getCurrentThreadID() - UnknownMachine" +#endif +} +/*==========================================================*/ +inline bool isBigEndian() +{ + short word = 0x4321; + if ((*(char *)&word) != 0x21) + return true; + else + return false; +} +/*==========================================================*/ +inline bool isLittleEndian() { return !isBigEndian(); } +/*==========================================================*/ +inline std::string getTimeStamp() +{ + time_t t = time(NULL); + tm *localTime = localtime(&t); + + std::stringstream tmp; + tmp.fill('0'); + + tmp << localTime->tm_year + 1900 << "." << std::setw(2) << localTime->tm_mon + 1 << "." << std::setw(2) + << localTime->tm_mday << "@" << std::setw(2) << localTime->tm_hour << "." << std::setw(2) << localTime->tm_min + << "." << std::setw(2) << localTime->tm_sec; + + return tmp.str(); +} +/*==========================================================*/ +// swap Byte Order +// usage: int test = 8; +// swapByteOrder((unsigned char*)& test, sizeof(int)) +//#define ByteSwap5(x) ByteSwap((unsigned char *) &x,sizeof(x)) +inline void swapByteOrder(unsigned char *toSwap, int length) +{ + int i = 0; + int j = length - 1; + while (i < j) { + std::swap(toSwap[i], toSwap[j]); + i++, j--; + } +} +////////////////////////////////////////////////////////////////////////// +// get host name +inline std::string getMachineName() +{ + char Name[150]; #if defined(UBSYSTEM_WINDOWS) || defined(UBSYSTEM_CYGWIN) - TCHAR infoBuf[150]; - DWORD bufCharCount = 150; - memset(Name, 0, 150); - if (GetComputerName(infoBuf, &bufCharCount)) - { - for (int i = 0; i<150; i++) - { + TCHAR infoBuf[150]; + DWORD bufCharCount = 150; + memset(Name, 0, 150); + if (GetComputerName(infoBuf, &bufCharCount)) { + for (int i = 0; i < 150; i++) { Name[i] = infoBuf[i]; - } - } - else - { - strcpy_s(Name, "Unknown_Host_Name"); - } + } + } else { + strcpy_s(Name, "Unknown_Host_Name"); + } #elif (defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_APPLE) || defined(UBSYSTEM_AIX)) && !defined(UBSYSTEM_CYGWIN) - memset(Name, 0, 150); - gethostname(Name, 150); + memset(Name, 0, 150); + gethostname(Name, 150); #endif - return std::string(Name); - } - - ////////////////////////////////////////////////////////////////////////// - // generic IfThenElse - start - ////////////////////////////////////////////////////////////////////////// - // primary template: yield second or third argument depending on first argument - template<bool C, typename Ta, typename Tb> - class IfThenElse; - - // partial specialization: true yields second argument - template<typename Ta, typename Tb> - class IfThenElse<true, Ta, Tb> { - public: - using ResultT = Ta; - }; - - // partial specialization: false yields third argument - template<typename Ta, typename Tb> - class IfThenElse<false, Ta, Tb> { - public: - using ResultT = Tb; - }; - ////////////////////////////////////////////////////////////////////////// - // generic IfThenElse - end - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - //help struct for overloading methods in template classes for specific types - ////////////////////////////////////////////////////////////////////////// - template< typename T> - struct type2type - { - using type = T; - }; - - - ////////////////////////////////////////////////////////////////////////// - // pair selector - ////////////////////////////////////////////////////////////////////////// - template <typename Pair> - struct select1st - { - using argument_type = Pair ; - using result_type = typename Pair::first_type ; - - const result_type& operator()(const argument_type &p) const - { - return p.first ; - } - }; - - template <typename Pair> - struct select2nd - { - using argument_type = Pair ; - using result_type = typename Pair::second_type ; - - const result_type& operator()(const argument_type &p) const - { - return p.second ; - } - }; + return std::string(Name); +} +////////////////////////////////////////////////////////////////////////// +// generic IfThenElse - start +////////////////////////////////////////////////////////////////////////// +// primary template: yield second or third argument depending on first argument +template <bool C, typename Ta, typename Tb> +class IfThenElse; + +// partial specialization: true yields second argument +template <typename Ta, typename Tb> +class IfThenElse<true, Ta, Tb> +{ +public: + using ResultT = Ta; +}; + +// partial specialization: false yields third argument +template <typename Ta, typename Tb> +class IfThenElse<false, Ta, Tb> +{ +public: + using ResultT = Tb; +}; +////////////////////////////////////////////////////////////////////////// +// generic IfThenElse - end +////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////// +// help struct for overloading methods in template classes for specific types +////////////////////////////////////////////////////////////////////////// +template <typename T> +struct type2type { + using type = T; }; -#define UB_STATIC_ASSERT(expr) static_cast<void>(sizeof( UbSystem::ub_static_assert<expr> )); -//zum ueberpruefen von STATISCHEN ausdruecken waehrend der compile-zeit +////////////////////////////////////////////////////////////////////////// +// pair selector +////////////////////////////////////////////////////////////////////////// +template <typename Pair> +struct select1st { + using argument_type = Pair; + using result_type = typename Pair::first_type; + + const result_type &operator()(const argument_type &p) const { return p.first; } +}; + +template <typename Pair> +struct select2nd { + using argument_type = Pair; + using result_type = typename Pair::second_type; + + const result_type &operator()(const argument_type &p) const { return p.second; } +}; + +}; // namespace UbSystem + +#define UB_STATIC_ASSERT(expr) static_cast<void>(sizeof(UbSystem::ub_static_assert<expr>)); +// zum ueberpruefen von STATISCHEN ausdruecken waehrend der compile-zeit //--> Ausdruecke muessen schon ZUR compilerzeit auswertbar sein !!! -//Anwendung z.B. zur Ueberpruefung von Funktionalitaeten, wie z.B. bei UbMath::getNegativeInfinity<double>(); +// Anwendung z.B. zur Ueberpruefung von Funktionalitaeten, wie z.B. bei UbMath::getNegativeInfinity<double>(); // -//Grund fuer macro ist einfach, dass es besser anzuwenden ist in der praxis! -//ansonsten wuerde es so aussehen: +// Grund fuer macro ist einfach, dass es besser anzuwenden ist in der praxis! +// ansonsten wuerde es so aussehen: // UbSystem::ub_static_assert< aaa == 1 > test(); // da ist UB_STATIC_ASSERT(aaa == 1); schoener // -//um das zu vermeiden machtman hier diesen static_cast<void>(sizeof(...) ) -//Code-Snippet: +// um das zu vermeiden machtman hier diesen static_cast<void>(sizeof(...) ) +// Code-Snippet: // struct Test { const static bool m_const_bool = true; bool m_bool; }; // int main() { // UB_STATIC_ASSERT( Test::m_const_bool == true ); // --> okay, assert bestanden // UB_STATIC_ASSERT( Test::m_const_bool == false); //: -// --> assert nicht bestanden z.B. error C2027: use of undefined type 'UbSystem::ub_static_assert<__formal> with __formal = false --> funzt nicht. fehler im code -// UB_STATIC_ASSERT( Test::m_bool == true ); +// --> assert nicht bestanden z.B. error C2027: use of undefined type 'UbSystem::ub_static_assert<__formal> with +// __formal = false --> funzt nicht. fehler im code UB_STATIC_ASSERT( Test::m_bool == true ); // --> nicht erlaubt, da m_bool nicht statisch und nicht const ist. //} -#endif //UBSYSTEM_H +#endif // UBSYSTEM_H diff --git a/src/basics/basics/utilities/UbTiming.h b/src/basics/basics/utilities/UbTiming.h index 35181c419..a99c4ec39 100644 --- a/src/basics/basics/utilities/UbTiming.h +++ b/src/basics/basics/utilities/UbTiming.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,344 +33,321 @@ #ifndef UBTIMING_H #define UBTIMING_H -#include <string> -#include <limits> +#include <ctime> #include <iostream> +#include <limits> #include <sstream> +#include <string> #include <vector> -#include <ctime> #ifdef VF_MPI - #include <mpi.h> - #include <basics/parallel/PbMpi.h> -#endif //VF_MPI +#include <basics/parallel/PbMpi.h> +#include <mpi.h> +#endif // VF_MPI class UbTiming { public: - UbTiming() - { - this->duration = 0.0; - this->deltaT = 0.0; - this->startTime = 0; - this->name = "noname"; - } - /*==========================================================*/ - UbTiming(const std::string& name) - { - this->duration = 0.0; - this->deltaT = 0.0; - this->startTime = 0; - this->name = name; - } - /*==========================================================*/ - virtual ~UbTiming() = default; - /*==========================================================*/ - virtual void initTiming() - { - this->duration = 0.0; - } - /*==========================================================*/ - virtual void startTiming() - { - #if defined(VF_MPI) && !defined(CAB_RUBY) - this->startTime = PbMpi::Wtime(); - #else - this->startTime = (double)clock(); - #endif //VF_MPI - } - /*==========================================================*/ - virtual void initAndStartTiming() - { - this->initTiming(); - this->startTiming(); - } - /*==========================================================*/ - virtual void endTiming() - { - this->stopTiming(); - } - /*==========================================================*/ - virtual void stopTiming() - { - #if defined(VF_MPI) && !defined(CAB_RUBY) - this->deltaT = PbMpi::Wtime()-this->startTime; - #else - this->deltaT = ((double)clock()-this->startTime)/(double)CLOCKS_PER_SEC; - #endif //VF_MPI + UbTiming() + { + this->duration = 0.0; + this->deltaT = 0.0; + this->startTime = 0; + this->name = "noname"; + } + /*==========================================================*/ + UbTiming(const std::string &name) + { + this->duration = 0.0; + this->deltaT = 0.0; + this->startTime = 0; + this->name = name; + } + /*==========================================================*/ + virtual ~UbTiming() = default; + /*==========================================================*/ + virtual void initTiming() { this->duration = 0.0; } + /*==========================================================*/ + virtual void startTiming() + { +#if defined(VF_MPI) && !defined(CAB_RUBY) + this->startTime = PbMpi::Wtime(); +#else + this->startTime = (double)clock(); +#endif // VF_MPI + } + /*==========================================================*/ + virtual void initAndStartTiming() + { + this->initTiming(); + this->startTiming(); + } + /*==========================================================*/ + virtual void endTiming() { this->stopTiming(); } + /*==========================================================*/ + virtual void stopTiming() + { +#if defined(VF_MPI) && !defined(CAB_RUBY) + this->deltaT = PbMpi::Wtime() - this->startTime; +#else + this->deltaT = ((double)clock() - this->startTime) / (double)CLOCKS_PER_SEC; +#endif // VF_MPI - this->duration += this->deltaT; - } - /*==========================================================*/ - virtual double getDuration() const - { - return this->duration; - } - /*==========================================================*/ - virtual void setName(const std::string& name) - { - this->name = name; - } - /*==========================================================*/ - virtual std::string getName() const - { - return this->name; - } - /*==========================================================*/ - void start() - { - this->duration = 0.0; + this->duration += this->deltaT; + } + /*==========================================================*/ + virtual double getDuration() const { return this->duration; } + /*==========================================================*/ + virtual void setName(const std::string &name) { this->name = name; } + /*==========================================================*/ + virtual std::string getName() const { return this->name; } + /*==========================================================*/ + void start() + { + this->duration = 0.0; - #if defined(VF_MPI) && !defined(CAB_RUBY) - this->startTime = PbMpi::Wtime(); - #else - this->startTime = (double)clock(); - #endif //VF_MPI - } - /*==========================================================*/ - void pause() - { - #if defined(VF_MPI) && !defined(CAB_RUBY) - this->duration += PbMpi::Wtime()-this->startTime; - #else - this->duration +=((double)clock()-this->startTime)/(double)CLOCKS_PER_SEC; - #endif //VF_MPI - } - /*==========================================================*/ - void unpause() - { - #if defined(VF_MPI) && !defined(CAB_RUBY) - this->startTime = PbMpi::Wtime(); - #else - this->startTime = (double)clock(); - #endif //VF_MPI - } - /*==========================================================*/ - void stop() - { - #if defined(VF_MPI) && !defined(CAB_RUBY) - this->duration += PbMpi::Wtime()-this->startTime; - #else - this->duration +=((double)clock()-this->startTime)/(double)CLOCKS_PER_SEC; - #endif //VF_MPI - } - /*==========================================================*/ - double getTicks() const - { - #if defined(VF_MPI) && !defined(CAB_RUBY) - return PbMpi::Wtick(); - #else - return double(1.0)/double(CLOCKS_PER_SEC); - #endif //VF_MPI - } +#if defined(VF_MPI) && !defined(CAB_RUBY) + this->startTime = PbMpi::Wtime(); +#else + this->startTime = (double)clock(); +#endif // VF_MPI + } + /*==========================================================*/ + void pause() + { +#if defined(VF_MPI) && !defined(CAB_RUBY) + this->duration += PbMpi::Wtime() - this->startTime; +#else + this->duration += ((double)clock() - this->startTime) / (double)CLOCKS_PER_SEC; +#endif // VF_MPI + } + /*==========================================================*/ + void unpause() + { +#if defined(VF_MPI) && !defined(CAB_RUBY) + this->startTime = PbMpi::Wtime(); +#else + this->startTime = (double)clock(); +#endif // VF_MPI + } + /*==========================================================*/ + void stop() + { +#if defined(VF_MPI) && !defined(CAB_RUBY) + this->duration += PbMpi::Wtime() - this->startTime; +#else + this->duration += ((double)clock() - this->startTime) / (double)CLOCKS_PER_SEC; +#endif // VF_MPI + } + /*==========================================================*/ + double getTicks() const + { +#if defined(VF_MPI) && !defined(CAB_RUBY) + return PbMpi::Wtick(); +#else + return double(1.0) / double(CLOCKS_PER_SEC); +#endif // VF_MPI + } protected: - std::string name; + std::string name; - double startTime; - double duration; - double deltaT; + double startTime; + double duration; + double deltaT; }; #include <basics/utilities/UbSystem.h> //for definitons of system/OS type -#ifdef UBSYSTEM_APPLE //Apple hack - #include <mach/mach_time.h> - #include <ctime> - #include <cstdio> - inline void mach_absolute_difference(const uint64_t& end, const uint64_t& start, struct timespec *tp) - { - uint64_t difference = end - start; - static mach_timebase_info_data_t info = {0,0}; - - if (info.denom == 0) - mach_timebase_info(&info); - - uint64_t elapsednano = difference * (info.numer / info.denom); - - tp->tv_sec = elapsednano * 1e-9; - tp->tv_nsec = elapsednano - (tp->tv_sec * 1e9); - } +#ifdef UBSYSTEM_APPLE // Apple hack +#include <cstdio> +#include <ctime> +#include <mach/mach_time.h> +inline void mach_absolute_difference(const uint64_t &end, const uint64_t &start, struct timespec *tp) +{ + uint64_t difference = end - start; + static mach_timebase_info_data_t info = { 0, 0 }; + + if (info.denom == 0) + mach_timebase_info(&info); + + uint64_t elapsednano = difference * (info.numer / info.denom); + + tp->tv_sec = elapsednano * 1e-9; + tp->tv_nsec = elapsednano - (tp->tv_sec * 1e9); +} #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_AIX) - #include <ctime> - #include <unistd.h> // for sysconf - #include <pthread.h> +#include <ctime> +#include <pthread.h> +#include <unistd.h> // for sysconf #endif /*=========================================================================*/ -//! \brief Time Measuring -//! \details +//! \brief Time Measuring +//! \details //! example: //! \code -//! t=0 start -//! t=1 +//! t=0 start +//! t=1 //! t=2 stop -> return 2; getLapTime=2; getTotalTime 2; getLapTimes: 2 -//! t=3 -//! t=4 +//! t=3 +//! t=4 //! t=5 stop -> return 3; getLapTime=3; getTotalTime 5; getLapTimes: 2,3 //! t=6 stop -> return 1; getLapTime=1; getTotalTime 6; getLapTimes: 2,3,1 -//! t=7 -//! t=8 start ->no consideration of time 7 and 8 -//! t=9 +//! t=7 +//! t=8 start ->no consideration of time 7 and 8 +//! t=9 //! t=10 stop -> return 2; getLapTime=2; getTotalTime 8; getLapTimes: 2,3,1,2 //! t=11 resetAndStart -> Timer is reset and restarted //! t=12 -//! t=13 +//! t=13 //! t=14 stop -> return 3; getLapTime=3; getTotalTime 3; getLapTimes: 3 //! \endcode class UbTimer { public: - UbTimer(const bool& storeLapTimes = false) - : name("unamed"), storeLapTimes(storeLapTimes) - - { + UbTimer(const bool &storeLapTimes = false) : name("unamed"), storeLapTimes(storeLapTimes) {} + /*==========================================================*/ + UbTimer(const std::string &name, const bool &storeLapTimes = false) : name(name), storeLapTimes(storeLapTimes) {} + /*==========================================================*/ + virtual ~UbTimer() = default; + /*==========================================================*/ + double getLapTime() const { return this->lapTime; } + std::vector<double> getLapTimes() const { return this->lapTimes; } + void setName(const std::string &name) { this->name = name; } + std::string getName() const { return this->name; } + bool isRunning() const { return isMeasuring; } + bool isStoringLapTimes() const { return storeLapTimes; } + /*==========================================================*/ + void setStoreLapTimes(const bool &storeLapTimes) { this->storeLapTimes = storeLapTimes; } + /*==========================================================*/ + void start() + { + this->isMeasuring = true; + +#if defined(VF_MPI) && !defined(CAB_RUBY) + this->startTime = PbMpi::Wtime(); +#elif defined(UBSYSTEM_APPLE) + this->startTime = mach_absolute_time(); +#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_AIX) + timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + this->startTime = (double)(tp.tv_sec) * 1.0e9 + (double)(tp.tv_nsec); +#else + this->startTime = (double)clock(); +#endif // VF_MPI + } + /*==========================================================*/ + void resetAndStart() + { + this->reset(); + this->start(); + } + /*==========================================================*/ + // stop: - stops the calculation and returns the time elapsed since last start/stop + // - timing continues + double stop() + { + // if start() was never activated before: + if (!isMeasuring) + return 0.0; - } - /*==========================================================*/ - UbTimer(const std::string& name, const bool& storeLapTimes = false) - : name(name), storeLapTimes(storeLapTimes) - { +#if defined(VF_MPI) && !defined(CAB_RUBY) + double actTime = PbMpi::Wtime(); + this->lapTime = actTime - this->startTime; +#elif defined(UBSYSTEM_APPLE) + double actTime = mach_absolute_time(); + timespec tp; + mach_absolute_difference(actTime, this->startTime, &tp); + this->lapTime = tp.tv_sec + tp.tv_nsec * 1e-9; +#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_AIX) + timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + double actTime = (double)(tp.tv_sec) * 1.0e9 + (double)(tp.tv_nsec); + this->lapTime = (actTime - this->startTime) * 1.0e-9; +#else + double actTime = (double)clock(); + this->lapTime = (actTime - this->startTime) / (double)CLOCKS_PER_SEC; +#endif // VF_MPI - } - /*==========================================================*/ - virtual ~UbTimer() = default; - /*==========================================================*/ - double getLapTime() const { return this->lapTime; } - std::vector<double> getLapTimes() const { return this->lapTimes; } - void setName(const std::string& name) { this->name = name; } - std::string getName() const { return this->name; } - bool isRunning() const { return isMeasuring; } - bool isStoringLapTimes() const { return storeLapTimes; } - /*==========================================================*/ - void setStoreLapTimes(const bool& storeLapTimes) { this->storeLapTimes = storeLapTimes; } - /*==========================================================*/ - void start() - { - this->isMeasuring = true; + this->startTime = actTime; + this->totalTime += this->lapTime; + if (storeLapTimes) + lapTimes.push_back(this->lapTime); - #if defined(VF_MPI) && !defined(CAB_RUBY) - this->startTime = PbMpi::Wtime(); - #elif defined(UBSYSTEM_APPLE) - this->startTime = mach_absolute_time(); - #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_AIX) - timespec tp; - clock_gettime(CLOCK_REALTIME,&tp); - this->startTime = (double)(tp.tv_sec)*1.0e9 + (double)(tp.tv_nsec); - #else - this->startTime = (double)clock(); - #endif //VF_MPI - } - /*==========================================================*/ - void resetAndStart() { this->reset(); this->start(); } - /*==========================================================*/ - //stop: - stops the calculation and returns the time elapsed since last start/stop - // - timing continues - double stop() - { - //if start() was never activated before: - if(!isMeasuring) return 0.0; - - #if defined(VF_MPI) && !defined(CAB_RUBY) - double actTime = PbMpi::Wtime(); - this->lapTime = actTime-this->startTime; - #elif defined(UBSYSTEM_APPLE) - double actTime = mach_absolute_time(); - timespec tp; - mach_absolute_difference(actTime, this->startTime, &tp); - this->lapTime = tp.tv_sec + tp.tv_nsec*1e-9; - #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_AIX) - timespec tp; - clock_gettime(CLOCK_REALTIME,&tp); - double actTime = (double)(tp.tv_sec)*1.0e9 + (double)(tp.tv_nsec); - this->lapTime = (actTime-this->startTime)*1.0e-9; - #else - double actTime = (double)clock(); - this->lapTime = (actTime-this->startTime)/(double)CLOCKS_PER_SEC; - #endif //VF_MPI - - this->startTime = actTime; - this->totalTime += this->lapTime; - if(storeLapTimes) lapTimes.push_back(this->lapTime); + return lapTime; + } + /*==========================================================*/ + void reset() + { + this->isMeasuring = false; - return lapTime; - } - /*==========================================================*/ - void reset() - { - this->isMeasuring = false; - - this->startTime = 0.0; - this->totalTime = 0.0; - this->lapTime = 0.0; + this->startTime = 0.0; + this->totalTime = 0.0; + this->lapTime = 0.0; - lapTimes.resize(0); - } - /*==========================================================*/ - double getCurrentLapTime() const - { - //if start() was never activated before: - if(!isMeasuring) return 0.0; - - #if defined(VF_MPI) && !defined(CAB_RUBY) - return PbMpi::Wtime() - this->startTime; - #elif defined(UBSYSTEM_APPLE) - timespec tp; - mach_absolute_difference(mach_absolute_time(), this->startTime, &tp); - return tp.tv_sec + tp.tv_nsec*1e-9; - #elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_AIX) - timespec tp; - clock_gettime(CLOCK_REALTIME,&tp); - return ((double)(tp.tv_sec)*1.0e9 + (double)(tp.tv_nsec) - this->startTime)*1.0e-9; - #else - return ( (double)clock() - this->startTime ) / (double)CLOCKS_PER_SEC; - #endif //VF_MPI - - } - /*==========================================================*/ - double getTotalTime() const - { - return this->totalTime; - } - /*==========================================================*/ - std::string toString() - { - std::stringstream text; - text<<*this; - return text.str(); - } + lapTimes.resize(0); + } + /*==========================================================*/ + double getCurrentLapTime() const + { + // if start() was never activated before: + if (!isMeasuring) + return 0.0; - //ueberladene Operatoren - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, const UbTimer& timer) - { - os<<"UbTimer[totalTime="<<timer.totalTime<<"sec, lapTimes("; - for(std::size_t i=0; i<timer.lapTimes.size(); i++) os<<timer.lapTimes[i]<<","; - os<<")]"; - return os; - } +#if defined(VF_MPI) && !defined(CAB_RUBY) + return PbMpi::Wtime() - this->startTime; +#elif defined(UBSYSTEM_APPLE) + timespec tp; + mach_absolute_difference(mach_absolute_time(), this->startTime, &tp); + return tp.tv_sec + tp.tv_nsec * 1e-9; +#elif defined(UBSYSTEM_LINUX) || defined(UBSYSTEM_AIX) + timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + return ((double)(tp.tv_sec) * 1.0e9 + (double)(tp.tv_nsec) - this->startTime) * 1.0e-9; +#else + return ((double)clock() - this->startTime) / (double)CLOCKS_PER_SEC; +#endif // VF_MPI + } + /*==========================================================*/ + double getTotalTime() const { return this->totalTime; } + /*==========================================================*/ + std::string toString() + { + std::stringstream text; + text << *this; + return text.str(); + } + // ueberladene Operatoren + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, const UbTimer &timer) + { + os << "UbTimer[totalTime=" << timer.totalTime << "sec, lapTimes("; + for (std::size_t i = 0; i < timer.lapTimes.size(); i++) + os << timer.lapTimes[i] << ","; + os << ")]"; + return os; + } protected: - std::string name; - bool isMeasuring{false}; - bool storeLapTimes; + std::string name; + bool isMeasuring{ false }; + bool storeLapTimes; - double startTime{0.0}; - double totalTime{0.0}; - double lapTime{0.0}; - - std::vector<double> lapTimes; -}; + double startTime{ 0.0 }; + double totalTime{ 0.0 }; + double lapTime{ 0.0 }; + std::vector<double> lapTimes; +}; /*=========================================================================*/ -//! \brief Time Measuring -//! -//! \details UbProressTimer measures the time from its instantiation to destruction and spend the elapsed time on "os" in [s] -//! example: -//! \code +//! \brief Time Measuring +//! +//! \details UbProressTimer measures the time from its instantiation to destruction and spend the elapsed time on "os" +//! in [s] example: \code //! { //! UbProgressTimer timer; //! UbSystem::sleepS(10); @@ -380,36 +357,29 @@ protected: class UbProgressTimer : public UbTimer { public: - UbProgressTimer(const UbProgressTimer& rhs) = delete; + UbProgressTimer(const UbProgressTimer &rhs) = delete; - explicit UbProgressTimer( std::ostream & os = std::cout ) - : UbTimer(),os(os) - { - this->start(); - } - /*==========================================================*/ - ~UbProgressTimer() override - { - // A) Throwing an exception from a destructor is a Bad Thing. - // B) The progress_timer destructor does output which may throw. - // C) A progress_timer is usually not critical to the application. - // Therefore, wrap the I/O in a try block, catch and ignore all exceptions. - try + explicit UbProgressTimer(std::ostream &os = std::cout) : UbTimer(), os(os) { this->start(); } + /*==========================================================*/ + ~UbProgressTimer() override { - // use istream instead of ios_base to workaround GNU problem (Greg Chicares) - std::istream::fmtflags old_flags = os.setf( std::istream::fixed, - std::istream::floatfield ); - std::streamsize old_prec = os.precision( 2 ); - os << stop() << " s" << std::endl; - os.flags( old_flags ); - os.precision( old_prec ); + // A) Throwing an exception from a destructor is a Bad Thing. + // B) The progress_timer destructor does output which may throw. + // C) A progress_timer is usually not critical to the application. + // Therefore, wrap the I/O in a try block, catch and ignore all exceptions. + try { + // use istream instead of ios_base to workaround GNU problem (Greg Chicares) + std::istream::fmtflags old_flags = os.setf(std::istream::fixed, std::istream::floatfield); + std::streamsize old_prec = os.precision(2); + os << stop() << " s" << std::endl; + os.flags(old_flags); + os.precision(old_prec); + } catch (...) { + } // eat any exceptions } - catch (...) {} // eat any exceptions - } private: - std::ostream & os; + std::ostream &os; }; - -#endif //UBTIMING_H +#endif // UBTIMING_H diff --git a/src/basics/basics/utilities/UbTuple.h b/src/basics/basics/utilities/UbTuple.h index f081f2e9e..fe9c787ce 100644 --- a/src/basics/basics/utilities/UbTuple.h +++ b/src/basics/basics/utilities/UbTuple.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,8 +34,8 @@ #define UBTUPLE_H #include <iostream> -#include <string> #include <ostream> +#include <string> ////////////////////////////////////////////////////////////////////////// //! \brief A class implements a tuple @@ -62,7 +62,7 @@ //! val<2>(t3) = 42; //! val<3>(t3) = 0.2; //! t3 = makeUbTuple(false, 23, 13.13); -//! +//! //! std::cout << val<1>(t3) << ", "; //! std::cout << val<2>(t3) << ", "; //! std::cout << val<3>(t3) << std::endl; @@ -75,343 +75,347 @@ //! \endcode template <typename T> -class UbTypeOp // primary template -{ +class UbTypeOp // primary template +{ public: - using ArgT = T; - using BareT = T; - using ConstT = const T; - using RefT = T &; - using RefBareT = T &; - using RefConstT = const T &; + using ArgT = T; + using BareT = T; + using ConstT = const T; + using RefT = T &; + using RefBareT = T &; + using RefConstT = const T &; }; /**** end of typeop1.hpp ****/ // partial specialization for const /********************************** -* typeop2.hpp: -**********************************/ + * typeop2.hpp: + **********************************/ template <typename T> -class UbTypeOp <T const> // partial specialization for const types -{ - public: - using ArgT = const T; - using BareT = T; - using ConstT = const T; - using RefT = const T &; - using RefBareT = T &; - using RefConstT = const T &; +class UbTypeOp<T const> // partial specialization for const types +{ +public: + using ArgT = const T; + using BareT = T; + using ConstT = const T; + using RefT = const T &; + using RefBareT = T &; + using RefConstT = const T &; }; /**** end of typeop2.hpp ****/ // partial specialization for references /********************************** -* typeop3.hpp: -**********************************/ + * typeop3.hpp: + **********************************/ template <typename T> -class UbTypeOp <T&> // partial specialization for references +class UbTypeOp<T &> // partial specialization for references { public: - using ArgT = T &; - using BareT = typename UbTypeOp<T>::BareT; - using ConstT = const T; - using RefT = T &; - using RefBareT = typename UbTypeOp<T>::BareT &; - using RefConstT = const T &; + using ArgT = T &; + using BareT = typename UbTypeOp<T>::BareT; + using ConstT = const T; + using RefT = T &; + using RefBareT = typename UbTypeOp<T>::BareT &; + using RefConstT = const T &; }; /**** end of typeop3.hpp ****/ // full specialization for void /********************************** -* typeop4.hpp: -**********************************/ -template<> -class UbTypeOp <void> // full specialization for void + * typeop4.hpp: + **********************************/ +template <> +class UbTypeOp<void> // full specialization for void { public: - using ArgT = void; - using BareT = void; - using ConstT = const void; - using RefT = void; - using RefBareT = void; - using RefConstT = void; + using ArgT = void; + using BareT = void; + using ConstT = const void; + using RefT = void; + using RefBareT = void; + using RefConstT = void; }; /**** end of typeop4.hpp ****/ template <typename T1, typename T2> -class UbDuo; +class UbDuo; template <typename T1, typename T2> -std::ostream& operator << (std::ostream& os, UbDuo<T1, T2> const& d1); +std::ostream &operator<<(std::ostream &os, UbDuo<T1, T2> const &d1); -//duo1.hpp +// duo1.hpp template <typename T1, typename T2> -class UbDuo +class UbDuo { public: - using Type1 = T1; // type of first field - using Type2 = T2; // type of second field - enum { N = 2 }; // number of fields + using Type1 = T1; // type of first field + using Type2 = T2; // type of second field + enum { N = 2 }; // number of fields public: - // constructors - UbDuo() : value1(), value2() { } - UbDuo (T1 const & a, T2 const & b) : value1(a), value2(b) { } - - // for implicit type conversion during construction - template <typename U1, typename U2> - UbDuo (UbDuo<U1,U2> const & d) : value1(d.v1()), value2(d.v2()) { } - - // for implicit type conversion during assignments - template <typename U1, typename U2> - UbDuo<T1, T2>& operator = (UbDuo<U1,U2> const & d) - { - value1 = d.v1();//value1; - value2 = d.v2();//value2; - return *this; - } - - // field access - T1& v1() { return value1; } - T1 const& v1() const { return value1; } - - T2& v2() { return value2; } - T2 const& v2() const { return value2; } + // constructors + UbDuo() : value1(), value2() {} + UbDuo(T1 const &a, T2 const &b) : value1(a), value2(b) {} + + // for implicit type conversion during construction + template <typename U1, typename U2> + UbDuo(UbDuo<U1, U2> const &d) : value1(d.v1()), value2(d.v2()) + { + } + + // for implicit type conversion during assignments + template <typename U1, typename U2> + UbDuo<T1, T2> &operator=(UbDuo<U1, U2> const &d) + { + value1 = d.v1(); // value1; + value2 = d.v2(); // value2; + return *this; + } + + // field access + T1 &v1() { return value1; } + T1 const &v1() const { return value1; } + + T2 &v2() { return value2; } + T2 const &v2() const { return value2; } private: - T1 value1; // value of first field - T2 value2; // value of second field + T1 value1; // value of first field + T2 value2; // value of second field }; // comparison operators (allow mixed types): -template <typename T1, typename T2,typename U1, typename U2> -inline bool operator == (UbDuo<T1,T2> const& d1, UbDuo<U1,U2> const& d2) +template <typename T1, typename T2, typename U1, typename U2> +inline bool operator==(UbDuo<T1, T2> const &d1, UbDuo<U1, U2> const &d2) { - return d1.v1()==d2.v1() && d1.v2()==d2.v2(); + return d1.v1() == d2.v1() && d1.v2() == d2.v2(); } -template <typename T1, typename T2,typename U1, typename U2> -inline bool operator != (UbDuo<T1,T2> const& d1, UbDuo<U1,U2> const& d2) +template <typename T1, typename T2, typename U1, typename U2> +inline bool operator!=(UbDuo<T1, T2> const &d1, UbDuo<U1, U2> const &d2) { - return !(d1==d2); + return !(d1 == d2); } -template <typename T1, typename T2,typename U1, typename U2> -inline bool operator < (UbDuo<T1,T2> const& d1, UbDuo<U1,U2> const& d2) +template <typename T1, typename T2, typename U1, typename U2> +inline bool operator<(UbDuo<T1, T2> const &d1, UbDuo<U1, U2> const &d2) { - if (d1.v1() < d2.v1() ) return true; - else if(d1.v1() == d2.v1() ) return d1.v2() < d2.v2(); + if (d1.v1() < d2.v1()) + return true; + else if (d1.v1() == d2.v1()) + return d1.v2() < d2.v2(); - return false; + return false; } template <typename T1, typename T2> -std::ostream& operator << (std::ostream& os, UbDuo<T1, T2> const& d1) +std::ostream &operator<<(std::ostream &os, UbDuo<T1, T2> const &d1) { os << d1.v1() << ", " << d1.v2(); return os; } // convenience function for creation and initialization -template <typename T1, typename T2> -inline UbDuo<T1,T2> makeUbDuo(T1 const & a, T2 const & b) +template <typename T1, typename T2> +inline UbDuo<T1, T2> makeUbDuo(T1 const &a, T2 const &b) { - return UbDuo<T1,T2>(a,b); + return UbDuo<T1, T2>(a, b); } -//duo2.hpp +// duo2.hpp template <typename A, typename B, typename C> -class UbDuo<A, UbDuo<B,C> > +class UbDuo<A, UbDuo<B, C>> { public: - using T1 = A; // type of first field - using T2 = UbDuo<B, C>; // type of second field - enum { N = UbDuo<B,C>::N + 1 }; // number of fields - + using T1 = A; // type of first field + using T2 = UbDuo<B, C>; // type of second field + enum { N = UbDuo<B, C>::N + 1 }; // number of fields + public: - // constructors - UbDuo() : value1(), value2() { } - UbDuo (T1 const & a, T2 const & b) : value1(a), value2(b) { } - - // for implicit type conversion during construction - template <typename U1, typename U2> - UbDuo (UbDuo<U1,U2> const & d) : value1(d.v1()), value2(d.v2()) { } - - // for implicit type conversion during assignments - template <typename U1, typename U2> - UbDuo<T1, T2>& operator = (UbDuo<U1,U2> const & d) - { - value1 = d.v1();//value1; - value2 = d.v2();//value2; - return *this; - } - - // field access - T1& v1() { return value1; } - T1 const& v1() const { return value1; } - - T2& v2() { return value2; } - T2 const& v2() const { return value2; } + // constructors + UbDuo() : value1(), value2() {} + UbDuo(T1 const &a, T2 const &b) : value1(a), value2(b) {} + + // for implicit type conversion during construction + template <typename U1, typename U2> + UbDuo(UbDuo<U1, U2> const &d) : value1(d.v1()), value2(d.v2()) + { + } + + // for implicit type conversion during assignments + template <typename U1, typename U2> + UbDuo<T1, T2> &operator=(UbDuo<U1, U2> const &d) + { + value1 = d.v1(); // value1; + value2 = d.v2(); // value2; + return *this; + } + + // field access + T1 &v1() { return value1; } + T1 const &v1() const { return value1; } + + T2 &v2() { return value2; } + T2 const &v2() const { return value2; } private: - T1 value1; // value of first field - T2 value2; // value of second field + T1 value1; // value of first field + T2 value2; // value of second field }; -//duo3.hpp +// duo3.hpp // primary template for type of Nth field of (duo) T template <int N, typename T> -class UbDuoT +class UbDuoT { public: - using ResultT = void; // in general, the result type is void + using ResultT = void; // in general, the result type is void }; // specialization for 1st field of a plain duo template <typename A, typename B> -class UbDuoT<1, UbDuo<A,B> > +class UbDuoT<1, UbDuo<A, B>> { public: - using ResultT = A; + using ResultT = A; }; // specialization for 2nd field of a plain duo template <typename A, typename B> -class UbDuoT<2, UbDuo<A,B> > +class UbDuoT<2, UbDuo<A, B>> { public: - using ResultT = B; + using ResultT = B; }; // specialization for Nth field of a recursive duo template <int N, typename A, typename B, typename C> -class UbDuoT<N, UbDuo<A, UbDuo<B,C> > > +class UbDuoT<N, UbDuo<A, UbDuo<B, C>>> { public: - using ResultT = typename UbDuoT<N - 1, UbDuo<B, C> >::ResultT; + using ResultT = typename UbDuoT<N - 1, UbDuo<B, C>>::ResultT; }; // specialization for 1st field of a recursive duo template <typename A, typename B, typename C> -class UbDuoT<1, UbDuo<A, UbDuo<B,C> > > +class UbDuoT<1, UbDuo<A, UbDuo<B, C>>> { public: - using ResultT = A; + using ResultT = A; }; // specialization for 2nd field of a recursive duo template <typename A, typename B, typename C> -class UbDuoT<2, UbDuo<A, UbDuo<B,C> > > +class UbDuoT<2, UbDuo<A, UbDuo<B, C>>> { public: - using ResultT = B; + using ResultT = B; }; -//duo4.hpp +// duo4.hpp // primary template for value of Nth field of (duo) T template <int N, typename T> -class DuoValue +class DuoValue { public: - static void get(T&) { } // in general, we have no value - static void get(T const&) { } + static void get(T &) {} // in general, we have no value + static void get(T const &) {} }; // specialization for 1st field of a plain duo template <typename A, typename B> -class DuoValue<1, UbDuo<A, B> > +class DuoValue<1, UbDuo<A, B>> { public: - static A& get(UbDuo<A, B> &d) { return d.v1(); } - static A const& get(UbDuo<A, B> const &d) { return d.v1(); } + static A &get(UbDuo<A, B> &d) { return d.v1(); } + static A const &get(UbDuo<A, B> const &d) { return d.v1(); } }; // specialization for 2nd field of a plain duo template <typename A, typename B> -class DuoValue<2, UbDuo<A, B> > +class DuoValue<2, UbDuo<A, B>> { public: - static B& get(UbDuo<A, B> &d) { return d.v2(); } - static B const& get(UbDuo<A, B> const &d) { return d.v2(); } + static B &get(UbDuo<A, B> &d) { return d.v2(); } + static B const &get(UbDuo<A, B> const &d) { return d.v2(); } }; // specialization for Nth field of recursive duo template <int N, typename A, typename B, typename C> -struct DuoValue<N, UbDuo<A, UbDuo<B,C> > > -{ - static typename UbTypeOp<typename UbDuoT<N-1, UbDuo<B,C> >::ResultT>::RefT get(UbDuo<A, UbDuo<B,C> > &d) - { - return DuoValue<N-1, UbDuo<B,C> >::get(d.v2()); - } - static typename UbTypeOp<typename UbDuoT<N-1, UbDuo<B,C> >::ResultT>::RefConstT get(UbDuo<A, UbDuo<B,C> > const &d) - { - return DuoValue<N-1, UbDuo<B,C> >::get(d.v2()); - } +struct DuoValue<N, UbDuo<A, UbDuo<B, C>>> { + static typename UbTypeOp<typename UbDuoT<N - 1, UbDuo<B, C>>::ResultT>::RefT get(UbDuo<A, UbDuo<B, C>> &d) + { + return DuoValue<N - 1, UbDuo<B, C>>::get(d.v2()); + } + static typename UbTypeOp<typename UbDuoT<N - 1, UbDuo<B, C>>::ResultT>::RefConstT + get(UbDuo<A, UbDuo<B, C>> const &d) + { + return DuoValue<N - 1, UbDuo<B, C>>::get(d.v2()); + } }; // specialization for 1st field of recursive duo template <typename A, typename B, typename C> -class DuoValue<1, UbDuo<A, UbDuo<B,C> > > +class DuoValue<1, UbDuo<A, UbDuo<B, C>>> { public: - static A& get(UbDuo<A, UbDuo<B,C> > &d) { return d.v1(); } - static A const& get(UbDuo<A, UbDuo<B,C> > const &d) { return d.v1(); } + static A &get(UbDuo<A, UbDuo<B, C>> &d) { return d.v1(); } + static A const &get(UbDuo<A, UbDuo<B, C>> const &d) { return d.v1(); } }; // specialization for 2nd field of recursive duo template <typename A, typename B, typename C> -class DuoValue<2, UbDuo<A, UbDuo<B,C> > > +class DuoValue<2, UbDuo<A, UbDuo<B, C>>> { public: - static B& get(UbDuo<A, UbDuo<B,C> > &d) { return d.v2().v1(); } - static B const& get(UbDuo<A, UbDuo<B,C> > const &d) { return d.v2().v1(); } + static B &get(UbDuo<A, UbDuo<B, C>> &d) { return d.v2().v1(); } + static B const &get(UbDuo<A, UbDuo<B, C>> const &d) { return d.v2().v1(); } }; -//duo5.hpp +// duo5.hpp // return Nth value of variable duo -template <int N, typename A, typename B> -inline typename UbTypeOp<typename UbDuoT<N, UbDuo<A, B> >::ResultT>::RefT val(UbDuo<A, B>& d) +template <int N, typename A, typename B> +inline typename UbTypeOp<typename UbDuoT<N, UbDuo<A, B>>::ResultT>::RefT val(UbDuo<A, B> &d) { - return DuoValue<N, UbDuo<A, B> >::get(d); + return DuoValue<N, UbDuo<A, B>>::get(d); } // return Nth value of constant duo -template <int N, typename A, typename B> -inline typename UbTypeOp<typename UbDuoT<N, UbDuo<A, B> >::ResultT>::RefConstT val(UbDuo<A, B> const& d) +template <int N, typename A, typename B> +inline typename UbTypeOp<typename UbDuoT<N, UbDuo<A, B>>::ResultT>::RefConstT val(UbDuo<A, B> const &d) { - return DuoValue<N, UbDuo<A, B> >::get(d); + return DuoValue<N, UbDuo<A, B>>::get(d); } -//duo6.hpp +// duo6.hpp // partial specialization for UbDuo<> with only c1 field template <typename A> -struct UbDuo<A,void> -{ +struct UbDuo<A, void> { public: - using T1 = A; // type of first field - using T2 = void; // type of second field - enum { N = 1 }; // number of fields + using T1 = A; // type of first field + using T2 = void; // type of second field + enum { N = 1 }; // number of fields private: - T1 value1; // value of first field + T1 value1; // value of first field public: - // constructors - UbDuo() : value1() { } - UbDuo (T1 const & a) : value1(a) { } + // constructors + UbDuo() : value1() {} + UbDuo(T1 const &a) : value1(a) {} - // field access - T1& v1() { return value1; } - T1 const& v1() const { return value1; } - - void v2() { } - void v2() const { } + // field access + T1 &v1() { return value1; } + T1 const &v1() const { return value1; } + void v2() {} + void v2() const {} }; -//tupel1.hpp +// tupel1.hpp // type that represents unused type parameters -class UbNullT +class UbNullT { }; @@ -440,7 +444,7 @@ class UbNullT //! val<2>(t3) = 42; //! val<3>(t3) = 0.2; //! t3 = makeUbTuple(false, 23, 13.13); -//! +//! //! std::cout << val<1>(t3) << ", "; //! std::cout << val<2>(t3) << ", "; //! std::cout << val<3>(t3) << std::endl; @@ -453,181 +457,164 @@ class UbNullT //! \endcode // UbTuple<> in general derives from UbTuple<> with c1 more UbNullT -template <typename P1, - typename P2 = UbNullT, - typename P3 = UbNullT, - typename P4 = UbNullT, - typename P5 = UbNullT, - typename P6 = UbNullT, - typename P7 = UbNullT, - typename P8 = UbNullT > -class UbTuple : public UbDuo<P1, typename UbTuple<P2,P3,P4,P5,P6,P7,P8,UbNullT>::BaseT> +template <typename P1, typename P2 = UbNullT, typename P3 = UbNullT, typename P4 = UbNullT, typename P5 = UbNullT, + typename P6 = UbNullT, typename P7 = UbNullT, typename P8 = UbNullT> +class UbTuple : public UbDuo<P1, typename UbTuple<P2, P3, P4, P5, P6, P7, P8, UbNullT>::BaseT> { public: - using BaseT = UbDuo<P1, typename UbTuple<P2, P3, P4, P5, P6, P7, P8, UbNullT>::BaseT>; - - // constructor: - UbTuple() = default; - UbTuple( typename UbTypeOp<P1>::RefConstT a1, - typename UbTypeOp<P2>::RefConstT a2, - typename UbTypeOp<P3>::RefConstT a3 = UbNullT(), - typename UbTypeOp<P4>::RefConstT a4 = UbNullT(), - typename UbTypeOp<P5>::RefConstT a5 = UbNullT(), - typename UbTypeOp<P6>::RefConstT a6 = UbNullT(), - typename UbTypeOp<P7>::RefConstT a7 = UbNullT(), - typename UbTypeOp<P8>::RefConstT a8 = UbNullT() ) - : BaseT(a1, UbTuple<P2,P3,P4,P5,P6,P7,P8,UbNullT>(a2,a3,a4,a5,a6,a7,a8)) - { - } - - // for implicit type conversion during assignments - template <typename U1,typename U2, typename U3, typename U4, typename U5, typename U6, typename U7, typename U8 > - UbTuple<P1,P2,P3,P4,P5,P6,P7,P8>& operator = ( const UbTuple<U1,U2,U3,U4,U5,U6,U7,U8>& rhs) - { - this->BaseT::operator=( typename UbTuple<U1,U2,U3,U4,U5,U6,U7,U8>::BaseT(rhs) ); - return *this; - } - + using BaseT = UbDuo<P1, typename UbTuple<P2, P3, P4, P5, P6, P7, P8, UbNullT>::BaseT>; + + // constructor: + UbTuple() = default; + UbTuple(typename UbTypeOp<P1>::RefConstT a1, typename UbTypeOp<P2>::RefConstT a2, + typename UbTypeOp<P3>::RefConstT a3 = UbNullT(), typename UbTypeOp<P4>::RefConstT a4 = UbNullT(), + typename UbTypeOp<P5>::RefConstT a5 = UbNullT(), typename UbTypeOp<P6>::RefConstT a6 = UbNullT(), + typename UbTypeOp<P7>::RefConstT a7 = UbNullT(), typename UbTypeOp<P8>::RefConstT a8 = UbNullT()) + : BaseT(a1, UbTuple<P2, P3, P4, P5, P6, P7, P8, UbNullT>(a2, a3, a4, a5, a6, a7, a8)) + { + } + + // for implicit type conversion during assignments + template <typename U1, typename U2, typename U3, typename U4, typename U5, typename U6, typename U7, typename U8> + UbTuple<P1, P2, P3, P4, P5, P6, P7, P8> &operator=(const UbTuple<U1, U2, U3, U4, U5, U6, U7, U8> &rhs) + { + this->BaseT::operator=(typename UbTuple<U1, U2, U3, U4, U5, U6, U7, U8>::BaseT(rhs)); + return *this; + } }; // specialization to end deriving recursion template <typename P1, typename P2> -class UbTuple<P1,P2,UbNullT,UbNullT,UbNullT,UbNullT,UbNullT,UbNullT> : public UbDuo<P1,P2> { +class UbTuple<P1, P2, UbNullT, UbNullT, UbNullT, UbNullT, UbNullT, UbNullT> : public UbDuo<P1, P2> +{ public: - using BaseT = UbDuo<P1, P2>; - - // constructor: - UbTuple() = default; - UbTuple( typename UbTypeOp<P1>::RefConstT a1, - typename UbTypeOp<P2>::RefConstT a2, - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT() ) - : BaseT(a1, a2) - { - } - - // for implicit type conversion during assignments - template <typename U1,typename U2 > - UbTuple<P1,P2>& operator = ( const UbTuple<U1,U2>& rhs) - { - this->BaseT::operator=( typename UbTuple<U1,U2>::BaseT(rhs) ); - return *this; - } - + using BaseT = UbDuo<P1, P2>; + + // constructor: + UbTuple() = default; + UbTuple(typename UbTypeOp<P1>::RefConstT a1, typename UbTypeOp<P2>::RefConstT a2, + typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), + typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), + typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), typename UbTypeOp<UbNullT>::RefConstT = UbNullT()) + : BaseT(a1, a2) + { + } + + // for implicit type conversion during assignments + template <typename U1, typename U2> + UbTuple<P1, P2> &operator=(const UbTuple<U1, U2> &rhs) + { + this->BaseT::operator=(typename UbTuple<U1, U2>::BaseT(rhs)); + return *this; + } }; // specialization for singletons template <typename P1> -class UbTuple<P1,UbNullT,UbNullT,UbNullT,UbNullT,UbNullT,UbNullT,UbNullT> : public UbDuo<P1,void> +class UbTuple<P1, UbNullT, UbNullT, UbNullT, UbNullT, UbNullT, UbNullT, UbNullT> : public UbDuo<P1, void> { public: - using BaseT = UbDuo<P1, void>; - - // constructor: - UbTuple() = default; - UbTuple( typename UbTypeOp<P1>::RefConstT a1, - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), - typename UbTypeOp<UbNullT>::RefConstT = UbNullT() ) - : BaseT(a1) - { - } - - // for implicit type conversion during assignments - template <typename U1 > - UbTuple<P1>& operator = ( const UbTuple<U1>& rhs) - { - this->v1() = rhs.v1(); - return *this; - } - + using BaseT = UbDuo<P1, void>; + + // constructor: + UbTuple() = default; + UbTuple(typename UbTypeOp<P1>::RefConstT a1, typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), + typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), + typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), + typename UbTypeOp<UbNullT>::RefConstT = UbNullT(), typename UbTypeOp<UbNullT>::RefConstT = UbNullT()) + : BaseT(a1) + { + } + + // for implicit type conversion during assignments + template <typename U1> + UbTuple<P1> &operator=(const UbTuple<U1> &rhs) + { + this->v1() = rhs.v1(); + return *this; + } }; // convenience function for 1 argument -template <typename T1> +template <typename T1> inline UbTuple<T1> makeUbTuple(T1 const &a1) { - return UbTuple<T1>(a1); + return UbTuple<T1>(a1); } // convenience function for 2 arguments template <typename T1, typename T2> -inline UbTuple<T1,T2> makeUbTuple(T1 const &a1, T2 const &a2) +inline UbTuple<T1, T2> makeUbTuple(T1 const &a1, T2 const &a2) { - return UbTuple<T1,T2>(a1,a2); + return UbTuple<T1, T2>(a1, a2); } // convenience function for 3 arguments template <typename T1, typename T2, typename T3> -inline UbTuple<T1,T2,T3> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3) +inline UbTuple<T1, T2, T3> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3) { - return UbTuple<T1,T2,T3>(a1,a2,a3); + return UbTuple<T1, T2, T3>(a1, a2, a3); } // convenience function for 4 arguments template <typename T1, typename T2, typename T3, typename T4> -inline UbTuple<T1,T2,T3,T4> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4) +inline UbTuple<T1, T2, T3, T4> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4) { - return UbTuple<T1,T2,T3,T4>(a1,a2,a3,a4); + return UbTuple<T1, T2, T3, T4>(a1, a2, a3, a4); } // convenience function for 5 arguments template <typename T1, typename T2, typename T3, typename T4, typename T5> -inline UbTuple<T1,T2,T3,T4,T5> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4,T5 const &a5) +inline UbTuple<T1, T2, T3, T4, T5> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4, T5 const &a5) { - return UbTuple<T1,T2,T3,T4,T5>(a1,a2,a3,a4,a5); + return UbTuple<T1, T2, T3, T4, T5>(a1, a2, a3, a4, a5); } // convenience function for 6 arguments template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> -inline UbTuple<T1,T2,T3,T4,T5,T6> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4, T5 const &a5, T6 const &a6) +inline UbTuple<T1, T2, T3, T4, T5, T6> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4, T5 const &a5, + T6 const &a6) { - return UbTuple<T1,T2,T3,T4,T5,T6>(a1,a2,a3,a4,a5,a6); + return UbTuple<T1, T2, T3, T4, T5, T6>(a1, a2, a3, a4, a5, a6); } // convenience function for 7 arguments template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> -inline UbTuple<T1,T2,T3,T4,T5,T6,T7> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4, T5 const &a5, T6 const &a6, T7 const &a7) +inline UbTuple<T1, T2, T3, T4, T5, T6, T7> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4, + T5 const &a5, T6 const &a6, T7 const &a7) { - return UbTuple<T1,T2,T3,T4,T5,T6,T7>(a1,a2,a3,a4,a5,a6,a7); + return UbTuple<T1, T2, T3, T4, T5, T6, T7>(a1, a2, a3, a4, a5, a6, a7); } // convenience function for 8 arguments template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> -inline UbTuple<T1,T2,T3,T4,T5,T6,T7,T8> makeUbTuple(T1 const &a1, T2 const &a2,T3 const &a3, T4 const &a4,T5 const &a5, T6 const &a6,T7 const &a7, T8 const &a8 ) +inline UbTuple<T1, T2, T3, T4, T5, T6, T7, T8> makeUbTuple(T1 const &a1, T2 const &a2, T3 const &a3, T4 const &a4, + T5 const &a5, T6 const &a6, T7 const &a7, T8 const &a8) { - return UbTuple<T1,T2,T3,T4,T5,T6,T7,T8>(a1,a2,a3,a4,a5,a6,a7,a8); + return UbTuple<T1, T2, T3, T4, T5, T6, T7, T8>(a1, a2, a3, a4, a5, a6, a7, a8); } -//some typedefs -using UbTupleFloat2 = UbTuple<float, float>; -using UbTupleFloat3 = UbTuple<float, float, float>; -using UbTupleInt2 = UbTuple<int, int>; -using UbTupleInt3 = UbTuple<int, int, int>; -using UbTupleInt4 = UbTuple<int, int, int, int>; -using UbTupleInt5 = UbTuple<int, int, int, int, int>; -using UbTupleInt6 = UbTuple<int, int, int, int, int, int>; -using UbTupleInt8 = UbTuple<int, int, int, int, int, int, int, int>; -using UbTupleUInt8 = UbTuple<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int>; -using UbTupleDouble2 = UbTuple<double, double>; -using UbTupleDouble3 = UbTuple<double, double, double>; -using UbTupleDouble4 = UbTuple<double, double, double, double>; -using UbTupleDouble6 = UbTuple<double, double, double, double, double, double>; +// some typedefs +using UbTupleFloat2 = UbTuple<float, float>; +using UbTupleFloat3 = UbTuple<float, float, float>; +using UbTupleInt2 = UbTuple<int, int>; +using UbTupleInt3 = UbTuple<int, int, int>; +using UbTupleInt4 = UbTuple<int, int, int, int>; +using UbTupleInt5 = UbTuple<int, int, int, int, int>; +using UbTupleInt6 = UbTuple<int, int, int, int, int, int>; +using UbTupleInt8 = UbTuple<int, int, int, int, int, int, int, int>; +using UbTupleUInt8 = UbTuple<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, + unsigned int, unsigned int>; +using UbTupleDouble2 = UbTuple<double, double>; +using UbTupleDouble3 = UbTuple<double, double, double>; +using UbTupleDouble4 = UbTuple<double, double, double, double>; +using UbTupleDouble6 = UbTuple<double, double, double, double, double, double>; using UbTupleStringDouble2 = UbTuple<std::string, double, double>; using UbTupleStringDouble3 = UbTuple<std::string, double, double, double>; -using UbTupleStringInt3 = UbTuple<std::string, int, int, int>; -using UbTupleShort4 = UbTuple<short, short, short, short>; -using UbTupleBool3 = UbTuple<bool, bool, bool>; -using UbTupleIntDouble2 = UbTuple<int, double, double>; -using UbTupleIntBool = UbTuple<int, bool>; - +using UbTupleStringInt3 = UbTuple<std::string, int, int, int>; +using UbTupleShort4 = UbTuple<short, short, short, short>; +using UbTupleBool3 = UbTuple<bool, bool, bool>; +using UbTupleIntDouble2 = UbTuple<int, double, double>; +using UbTupleIntBool = UbTuple<int, bool>; -#endif //UBTUPLE_H +#endif // UBTUPLE_H diff --git a/src/basics/basics/utilities/Vector3D.cpp b/src/basics/basics/utilities/Vector3D.cpp index 75ab1b814..6ff9dc873 100644 --- a/src/basics/basics/utilities/Vector3D.cpp +++ b/src/basics/basics/utilities/Vector3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,611 +35,490 @@ #include <cassert> #include <sstream> -#include <basics/utilities/UbMath.h> #include <basics/utilities/UbInfinity.h> +#include <basics/utilities/UbMath.h> - - -const Vector3D Vector3D::ZERO(0.0,0.0,0.0); -const Vector3D Vector3D::UNIT_X1(1.0,0.0,0.0); -const Vector3D Vector3D::UNIT_X2(0.0,1.0,0.0); -const Vector3D Vector3D::UNIT_X3(0.0,0.0,1.0); +const Vector3D Vector3D::ZERO(0.0, 0.0, 0.0); +const Vector3D Vector3D::UNIT_X1(1.0, 0.0, 0.0); +const Vector3D Vector3D::UNIT_X2(0.0, 1.0, 0.0); +const Vector3D Vector3D::UNIT_X3(0.0, 0.0, 1.0); /*=======================================================*/ -Vector3D::Vector3D() -{ - m_afTuple[0] = 0.0; - m_afTuple[1] = 0.0; - m_afTuple[2] = 0.0; -} -/*=======================================================*/ -Vector3D::Vector3D(const double& fX, const double& fY, const double& fZ) +Vector3D::Vector3D() { - m_afTuple[0] = fX; - m_afTuple[1] = fY; - m_afTuple[2] = fZ; + m_afTuple[0] = 0.0; + m_afTuple[1] = 0.0; + m_afTuple[2] = 0.0; } /*=======================================================*/ -Vector3D::Vector3D (const Vector3D& rkV) +Vector3D::Vector3D(const double &fX, const double &fY, const double &fZ) { - m_afTuple[0] = rkV.m_afTuple[0]; - m_afTuple[1] = rkV.m_afTuple[1]; - m_afTuple[2] = rkV.m_afTuple[2]; + m_afTuple[0] = fX; + m_afTuple[1] = fY; + m_afTuple[2] = fZ; } /*=======================================================*/ -std::string Vector3D::toString() const +Vector3D::Vector3D(const Vector3D &rkV) { - std::stringstream os; - os<< "Vector3D["<<m_afTuple[0]<<","<<m_afTuple[1]<<","<<m_afTuple[2]<<"]"; - return os.str(); + m_afTuple[0] = rkV.m_afTuple[0]; + m_afTuple[1] = rkV.m_afTuple[1]; + m_afTuple[2] = rkV.m_afTuple[2]; } /*=======================================================*/ -Vector3D::operator const double*() const +std::string Vector3D::toString() const { - return m_afTuple; + std::stringstream os; + os << "Vector3D[" << m_afTuple[0] << "," << m_afTuple[1] << "," << m_afTuple[2] << "]"; + return os.str(); } /*=======================================================*/ -Vector3D::operator double*() -{ - return m_afTuple; -} +Vector3D::operator const double *() const { return m_afTuple; } /*=======================================================*/ -double Vector3D::operator[](const int& i) const -{ - assert( i >= 0 && i <= 2 ); - return m_afTuple[i]; -} +Vector3D::operator double *() { return m_afTuple; } /*=======================================================*/ -double& Vector3D::operator[](const int& i) +double Vector3D::operator[](const int &i) const { - assert( i >= 0 && i <= 2 ); - return m_afTuple[i]; + assert(i >= 0 && i <= 2); + return m_afTuple[i]; } /*=======================================================*/ -double Vector3D::X1() const +double &Vector3D::operator[](const int &i) { - return m_afTuple[0]; + assert(i >= 0 && i <= 2); + return m_afTuple[i]; } /*=======================================================*/ -double& Vector3D::X1() -{ - return m_afTuple[0]; -} +double Vector3D::X1() const { return m_afTuple[0]; } /*=======================================================*/ -double Vector3D::X2() const -{ - return m_afTuple[1]; -} +double &Vector3D::X1() { return m_afTuple[0]; } /*=======================================================*/ -double& Vector3D::X2() -{ - return m_afTuple[1]; -} +double Vector3D::X2() const { return m_afTuple[1]; } /*=======================================================*/ -double Vector3D::X3() const -{ - return m_afTuple[2]; -} +double &Vector3D::X2() { return m_afTuple[1]; } /*=======================================================*/ -double& Vector3D::X3() -{ - return m_afTuple[2]; -} +double Vector3D::X3() const { return m_afTuple[2]; } /*=======================================================*/ -Vector3D& Vector3D::operator=(const Vector3D& rkV) +double &Vector3D::X3() { return m_afTuple[2]; } +/*=======================================================*/ +Vector3D &Vector3D::operator=(const Vector3D &rkV) { - if(this == &rkV) + if (this == &rkV) return *this; - m_afTuple[0] = rkV.m_afTuple[0]; - m_afTuple[1] = rkV.m_afTuple[1]; - m_afTuple[2] = rkV.m_afTuple[2]; - return *this; + m_afTuple[0] = rkV.m_afTuple[0]; + m_afTuple[1] = rkV.m_afTuple[1]; + m_afTuple[2] = rkV.m_afTuple[2]; + return *this; } /*=======================================================*/ -int Vector3D::CompareArrays(const Vector3D& rkV) const -{ - return memcmp(m_afTuple,rkV.m_afTuple,3*sizeof(double)); -} +int Vector3D::CompareArrays(const Vector3D &rkV) const { return memcmp(m_afTuple, rkV.m_afTuple, 3 * sizeof(double)); } /*=======================================================*/ -bool Vector3D::operator==(const Vector3D& rkV) const -{ - return CompareArrays(rkV) == 0; -} +bool Vector3D::operator==(const Vector3D &rkV) const { return CompareArrays(rkV) == 0; } /*=======================================================*/ -bool Vector3D::operator!=(const Vector3D& rkV) const -{ - return CompareArrays(rkV) != 0; -} +bool Vector3D::operator!=(const Vector3D &rkV) const { return CompareArrays(rkV) != 0; } /*=======================================================*/ -bool Vector3D::operator<(const Vector3D& rkV) const -{ - return CompareArrays(rkV) < 0; -} +bool Vector3D::operator<(const Vector3D &rkV) const { return CompareArrays(rkV) < 0; } /*=======================================================*/ -bool Vector3D::operator<=(const Vector3D& rkV) const -{ - return CompareArrays(rkV) <= 0; -} +bool Vector3D::operator<=(const Vector3D &rkV) const { return CompareArrays(rkV) <= 0; } /*=======================================================*/ -bool Vector3D::operator> (const Vector3D& rkV) const -{ - return CompareArrays(rkV) > 0; -} +bool Vector3D::operator>(const Vector3D &rkV) const { return CompareArrays(rkV) > 0; } /*=======================================================*/ -bool Vector3D::operator>=(const Vector3D& rkV) const -{ - return CompareArrays(rkV) >= 0; -} +bool Vector3D::operator>=(const Vector3D &rkV) const { return CompareArrays(rkV) >= 0; } /*=======================================================*/ -Vector3D Vector3D::operator+(const Vector3D& rkV) const +Vector3D Vector3D::operator+(const Vector3D &rkV) const { - return Vector3D( m_afTuple[0]+rkV.m_afTuple[0], - m_afTuple[1]+rkV.m_afTuple[1], - m_afTuple[2]+rkV.m_afTuple[2] ); + return Vector3D(m_afTuple[0] + rkV.m_afTuple[0], m_afTuple[1] + rkV.m_afTuple[1], m_afTuple[2] + rkV.m_afTuple[2]); } /*=======================================================*/ -Vector3D Vector3D::Add(Vector3D& vector) +Vector3D Vector3D::Add(Vector3D &vector) { - return Vector3D( m_afTuple[0]+vector.m_afTuple[0], - m_afTuple[1]+vector.m_afTuple[1], - m_afTuple[2]+vector.m_afTuple[2] ); + return Vector3D(m_afTuple[0] + vector.m_afTuple[0], m_afTuple[1] + vector.m_afTuple[1], + m_afTuple[2] + vector.m_afTuple[2]); } /*=======================================================*/ -Vector3D Vector3D::operator- (const Vector3D& rkV) const +Vector3D Vector3D::operator-(const Vector3D &rkV) const { - return Vector3D( m_afTuple[0]-rkV.m_afTuple[0], - m_afTuple[1]-rkV.m_afTuple[1], - m_afTuple[2]-rkV.m_afTuple[2] ); + return Vector3D(m_afTuple[0] - rkV.m_afTuple[0], m_afTuple[1] - rkV.m_afTuple[1], m_afTuple[2] - rkV.m_afTuple[2]); } /*=======================================================*/ -Vector3D Vector3D::Subtract(Vector3D& vector) +Vector3D Vector3D::Subtract(Vector3D &vector) { - return Vector3D( m_afTuple[0]-vector.m_afTuple[0], - m_afTuple[1]-vector.m_afTuple[1], - m_afTuple[2]-vector.m_afTuple[2] ); + return Vector3D(m_afTuple[0] - vector.m_afTuple[0], m_afTuple[1] - vector.m_afTuple[1], + m_afTuple[2] - vector.m_afTuple[2]); } /*=======================================================*/ -Vector3D Vector3D::operator*(const double& fScalar) const +Vector3D Vector3D::operator*(const double &fScalar) const { - return Vector3D( fScalar*m_afTuple[0], - fScalar*m_afTuple[1], - fScalar*m_afTuple[2] ); + return Vector3D(fScalar * m_afTuple[0], fScalar * m_afTuple[1], fScalar * m_afTuple[2]); } /*=======================================================*/ -Vector3D Vector3D::operator/(const double& fScalar) const +Vector3D Vector3D::operator/(const double &fScalar) const { - Vector3D kQuot; + Vector3D kQuot; - if ( fScalar != 0.0 ) - { - double fInvScalar = 1.0/fScalar; - kQuot.m_afTuple[0] = fInvScalar*m_afTuple[0]; - kQuot.m_afTuple[1] = fInvScalar*m_afTuple[1]; - kQuot.m_afTuple[2] = fInvScalar*m_afTuple[2]; - } - else - { - kQuot.m_afTuple[0] = Ub::inf; - kQuot.m_afTuple[1] = Ub::inf; - kQuot.m_afTuple[2] = Ub::inf; - } + if (fScalar != 0.0) { + double fInvScalar = 1.0 / fScalar; + kQuot.m_afTuple[0] = fInvScalar * m_afTuple[0]; + kQuot.m_afTuple[1] = fInvScalar * m_afTuple[1]; + kQuot.m_afTuple[2] = fInvScalar * m_afTuple[2]; + } else { + kQuot.m_afTuple[0] = Ub::inf; + kQuot.m_afTuple[1] = Ub::inf; + kQuot.m_afTuple[2] = Ub::inf; + } - return kQuot; + return kQuot; } /*=======================================================*/ -Vector3D Vector3D::operator-() const -{ - return Vector3D( -m_afTuple[0], - -m_afTuple[1], - -m_afTuple[2] ); -} +Vector3D Vector3D::operator-() const { return Vector3D(-m_afTuple[0], -m_afTuple[1], -m_afTuple[2]); } /*=======================================================*/ -Vector3D& Vector3D::operator+=(const Vector3D& rkV) +Vector3D &Vector3D::operator+=(const Vector3D &rkV) { - m_afTuple[0] += rkV.m_afTuple[0]; - m_afTuple[1] += rkV.m_afTuple[1]; - m_afTuple[2] += rkV.m_afTuple[2]; - return *this; + m_afTuple[0] += rkV.m_afTuple[0]; + m_afTuple[1] += rkV.m_afTuple[1]; + m_afTuple[2] += rkV.m_afTuple[2]; + return *this; } /*=======================================================*/ -Vector3D& Vector3D::operator-=(const Vector3D& rkV) +Vector3D &Vector3D::operator-=(const Vector3D &rkV) { - m_afTuple[0] -= rkV.m_afTuple[0]; - m_afTuple[1] -= rkV.m_afTuple[1]; - m_afTuple[2] -= rkV.m_afTuple[2]; - return *this; + m_afTuple[0] -= rkV.m_afTuple[0]; + m_afTuple[1] -= rkV.m_afTuple[1]; + m_afTuple[2] -= rkV.m_afTuple[2]; + return *this; } /*=======================================================*/ -Vector3D& Vector3D::operator*=(const double& fScalar) +Vector3D &Vector3D::operator*=(const double &fScalar) { - m_afTuple[0] *= fScalar; - m_afTuple[1] *= fScalar; - m_afTuple[2] *= fScalar; - return *this; + m_afTuple[0] *= fScalar; + m_afTuple[1] *= fScalar; + m_afTuple[2] *= fScalar; + return *this; } /*=======================================================*/ -Vector3D& Vector3D::operator/=(const double& fScalar) +Vector3D &Vector3D::operator/=(const double &fScalar) { - if ( !UbMath::zero(fScalar) ) - { - double fInvScalar = 1.0/fScalar; - m_afTuple[0] *= fInvScalar; - m_afTuple[1] *= fInvScalar; - m_afTuple[2] *= fInvScalar; - } - else - { - m_afTuple[0] = Ub::inf; - m_afTuple[1] = Ub::inf; - m_afTuple[2] = Ub::inf; - } + if (!UbMath::zero(fScalar)) { + double fInvScalar = 1.0 / fScalar; + m_afTuple[0] *= fInvScalar; + m_afTuple[1] *= fInvScalar; + m_afTuple[2] *= fInvScalar; + } else { + m_afTuple[0] = Ub::inf; + m_afTuple[1] = Ub::inf; + m_afTuple[2] = Ub::inf; + } - return *this; + return *this; } /*=======================================================*/ -Vector3D Vector3D::Scale(const double& x) +Vector3D Vector3D::Scale(const double &x) { - Vector3D PointA(0.0,0.0,0.0); - PointA.m_afTuple[0] = x * m_afTuple[0]; - PointA.m_afTuple[1] = x * m_afTuple[1]; - PointA.m_afTuple[2] = x * m_afTuple[2]; - return PointA; + Vector3D PointA(0.0, 0.0, 0.0); + PointA.m_afTuple[0] = x * m_afTuple[0]; + PointA.m_afTuple[1] = x * m_afTuple[1]; + PointA.m_afTuple[2] = x * m_afTuple[2]; + return PointA; } /*=======================================================*/ double Vector3D::Length() const { - return std::sqrt( m_afTuple[0]*m_afTuple[0] + - m_afTuple[1]*m_afTuple[1] + - m_afTuple[2]*m_afTuple[2] ); + return std::sqrt(m_afTuple[0] * m_afTuple[0] + m_afTuple[1] * m_afTuple[1] + m_afTuple[2] * m_afTuple[2]); } /*=======================================================*/ double Vector3D::SquaredLength() const { - return m_afTuple[0]*m_afTuple[0] + - m_afTuple[1]*m_afTuple[1] + - m_afTuple[2]*m_afTuple[2]; + return m_afTuple[0] * m_afTuple[0] + m_afTuple[1] * m_afTuple[1] + m_afTuple[2] * m_afTuple[2]; } /*=======================================================*/ -double Vector3D::Dot(const Vector3D& rkV) const +double Vector3D::Dot(const Vector3D &rkV) const { - return m_afTuple[0]*rkV.m_afTuple[0] + - m_afTuple[1]*rkV.m_afTuple[1] + - m_afTuple[2]*rkV.m_afTuple[2]; + return m_afTuple[0] * rkV.m_afTuple[0] + m_afTuple[1] * rkV.m_afTuple[1] + m_afTuple[2] * rkV.m_afTuple[2]; } /*=======================================================*/ double Vector3D::Normalize() { - double fLength = Length(); + double fLength = Length(); - if( !UbMath::zero(fLength) ) - { - double fInvLength = 1.0/fLength; - m_afTuple[0] *= fInvLength; - m_afTuple[1] *= fInvLength; - m_afTuple[2] *= fInvLength; - } - else - { - fLength = 0.0; - m_afTuple[0] = 0.0; - m_afTuple[1] = 0.0; - m_afTuple[2] = 0.0; - } + if (!UbMath::zero(fLength)) { + double fInvLength = 1.0 / fLength; + m_afTuple[0] *= fInvLength; + m_afTuple[1] *= fInvLength; + m_afTuple[2] *= fInvLength; + } else { + fLength = 0.0; + m_afTuple[0] = 0.0; + m_afTuple[1] = 0.0; + m_afTuple[2] = 0.0; + } - return fLength; + return fLength; } /*=======================================================*/ -Vector3D Vector3D::Cross(const Vector3D& rkV) const +Vector3D Vector3D::Cross(const Vector3D &rkV) const { - return Vector3D( m_afTuple[1]*rkV.m_afTuple[2] - m_afTuple[2]*rkV.m_afTuple[1], - m_afTuple[2]*rkV.m_afTuple[0] - m_afTuple[0]*rkV.m_afTuple[2], - m_afTuple[0]*rkV.m_afTuple[1] - m_afTuple[1]*rkV.m_afTuple[0] ); + return Vector3D(m_afTuple[1] * rkV.m_afTuple[2] - m_afTuple[2] * rkV.m_afTuple[1], + m_afTuple[2] * rkV.m_afTuple[0] - m_afTuple[0] * rkV.m_afTuple[2], + m_afTuple[0] * rkV.m_afTuple[1] - m_afTuple[1] * rkV.m_afTuple[0]); } /*=======================================================*/ -Vector3D Vector3D::UnitCross(const Vector3D& rkV) const +Vector3D Vector3D::UnitCross(const Vector3D &rkV) const { - Vector3D kCross( m_afTuple[1]*rkV.m_afTuple[2] - m_afTuple[2]*rkV.m_afTuple[1], - m_afTuple[2]*rkV.m_afTuple[0] - m_afTuple[0]*rkV.m_afTuple[2], - m_afTuple[0]*rkV.m_afTuple[1] - m_afTuple[1]*rkV.m_afTuple[0] ); - kCross.Normalize(); - return kCross; + Vector3D kCross(m_afTuple[1] * rkV.m_afTuple[2] - m_afTuple[2] * rkV.m_afTuple[1], + m_afTuple[2] * rkV.m_afTuple[0] - m_afTuple[0] * rkV.m_afTuple[2], + m_afTuple[0] * rkV.m_afTuple[1] - m_afTuple[1] * rkV.m_afTuple[0]); + kCross.Normalize(); + return kCross; } /*=======================================================*/ -void Vector3D::GetBarycentrics(const Vector3D& rkV0,const Vector3D& rkV1, const Vector3D& rkV2,const Vector3D& rkV3, double afBary[4]) const +void Vector3D::GetBarycentrics(const Vector3D &rkV0, const Vector3D &rkV1, const Vector3D &rkV2, const Vector3D &rkV3, + double afBary[4]) const { - // compute the vectors relative to V3 of the tetrahedron - Vector3D akDiff[4] = { rkV0 - rkV3, - rkV1 - rkV3, - rkV2 - rkV3, - *this - rkV3 }; + // compute the vectors relative to V3 of the tetrahedron + Vector3D akDiff[4] = { rkV0 - rkV3, rkV1 - rkV3, rkV2 - rkV3, *this - rkV3 }; + + // If the vertices have large magnitude, the linear system of + // equations for computing barycentric coordinates can be + // ill-conditioned. To avoid this, uniformly scale the tetrahedron + // edges to be of order 1. The scaling of all differences does not + // change the barycentric coordinates. + double fMax = 0.0, fValue = 0.0; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) { + fValue = std::fabs(akDiff[i][j]); + if (fValue > fMax) + fMax = fValue; + } + + // scale down only large data + if (UbMath::greater(fMax, 1.0)) { + double fInvMax = ((double)1.0) / fMax; + for (int i = 0; i < 4; i++) + akDiff[i] *= fInvMax; + } - // If the vertices have large magnitude, the linear system of - // equations for computing barycentric coordinates can be - // ill-conditioned. To avoid this, uniformly scale the tetrahedron - // edges to be of order 1. The scaling of all differences does not - // change the barycentric coordinates. - double fMax = 0.0,fValue=0.0; - for(int i=0; i<3; i++) - for (int j=0; j<3; j++) - { - fValue = std::fabs(akDiff[i][j]); - if ( fValue > fMax ) fMax = fValue; - } - - // scale down only large data - if(UbMath::greater(fMax,1.0) ) - { - double fInvMax = ((double)1.0)/fMax; - for( int i=0; i<4; i++) - akDiff[i] *= fInvMax; - } + double fDet = akDiff[0].Dot(akDiff[1].Cross(akDiff[2])); + Vector3D kE1cE2 = akDiff[1].Cross(akDiff[2]); + Vector3D kE2cE0 = akDiff[2].Cross(akDiff[0]); + Vector3D kE0cE1 = akDiff[0].Cross(akDiff[1]); - double fDet = akDiff[0].Dot(akDiff[1].Cross(akDiff[2])); - Vector3D kE1cE2 = akDiff[1].Cross(akDiff[2]); - Vector3D kE2cE0 = akDiff[2].Cross(akDiff[0]); - Vector3D kE0cE1 = akDiff[0].Cross(akDiff[1]); - - if( !UbMath::zero( fDet ) ) - { - double fInvDet = 1.0/fDet; - afBary[0] = akDiff[3].Dot(kE1cE2)*fInvDet; - afBary[1] = akDiff[3].Dot(kE2cE0)*fInvDet; - afBary[2] = akDiff[3].Dot(kE0cE1)*fInvDet; - afBary[3] = 1.0 - afBary[0] - afBary[1] - afBary[2]; - } - else - { - // The tetrahedron is potentially flat. Determine the face of - // maximum area and compute barycentric coordinates with respect - // to that face. - Vector3D kE02 = rkV0 - rkV2; - Vector3D kE12 = rkV1 - rkV2; - Vector3D kE02cE12 = kE02.Cross(kE12); - double fMaxSqrArea = kE02cE12.SquaredLength(); - int iMaxIndex = 3; - double fSqrArea = kE0cE1.SquaredLength(); - if ( fSqrArea > fMaxSqrArea ) - { - iMaxIndex = 0; - fMaxSqrArea = fSqrArea; - } - fSqrArea = kE1cE2.SquaredLength(); - if ( fSqrArea > fMaxSqrArea ) - { - iMaxIndex = 1; - fMaxSqrArea = fSqrArea; - } - fSqrArea = kE2cE0.SquaredLength(); - if ( fSqrArea > fMaxSqrArea ) - { - iMaxIndex = 2; - fMaxSqrArea = fSqrArea; - } + if (!UbMath::zero(fDet)) { + double fInvDet = 1.0 / fDet; + afBary[0] = akDiff[3].Dot(kE1cE2) * fInvDet; + afBary[1] = akDiff[3].Dot(kE2cE0) * fInvDet; + afBary[2] = akDiff[3].Dot(kE0cE1) * fInvDet; + afBary[3] = 1.0 - afBary[0] - afBary[1] - afBary[2]; + } else { + // The tetrahedron is potentially flat. Determine the face of + // maximum area and compute barycentric coordinates with respect + // to that face. + Vector3D kE02 = rkV0 - rkV2; + Vector3D kE12 = rkV1 - rkV2; + Vector3D kE02cE12 = kE02.Cross(kE12); + double fMaxSqrArea = kE02cE12.SquaredLength(); + int iMaxIndex = 3; + double fSqrArea = kE0cE1.SquaredLength(); + if (fSqrArea > fMaxSqrArea) { + iMaxIndex = 0; + fMaxSqrArea = fSqrArea; + } + fSqrArea = kE1cE2.SquaredLength(); + if (fSqrArea > fMaxSqrArea) { + iMaxIndex = 1; + fMaxSqrArea = fSqrArea; + } + fSqrArea = kE2cE0.SquaredLength(); + if (fSqrArea > fMaxSqrArea) { + iMaxIndex = 2; + fMaxSqrArea = fSqrArea; + } - if (UbMath::greater(fMaxSqrArea,0.0) ) - { - double fInvSqrArea = 1.0/fMaxSqrArea; - Vector3D kTmp; - if( iMaxIndex==0 ) - { - kTmp = akDiff[3].Cross(akDiff[1]); - afBary[0] = kE0cE1.Dot(kTmp)*fInvSqrArea; - kTmp = akDiff[0].Cross(akDiff[3]); - afBary[1] = kE0cE1.Dot(kTmp)*fInvSqrArea; - afBary[2] = 0.0; - afBary[3] = 1.0 - afBary[0] - afBary[1]; - } - else if( iMaxIndex == 1 ) - { - afBary[0] = 0.0; - kTmp = akDiff[3].Cross(akDiff[2]); - afBary[1] = kE1cE2.Dot(kTmp)*fInvSqrArea; - kTmp = akDiff[1].Cross(akDiff[3]); - afBary[2] = kE1cE2.Dot(kTmp)*fInvSqrArea; - afBary[3] = 1.0 - afBary[1] - afBary[2]; - } - else if( iMaxIndex == 2 ) - { - kTmp = akDiff[2].Cross(akDiff[3]); - afBary[0] = kE2cE0.Dot(kTmp)*fInvSqrArea; - afBary[1] = 0.0; - kTmp = akDiff[3].Cross(akDiff[0]); - afBary[2] = kE2cE0.Dot(kTmp)*fInvSqrArea; - afBary[3] = 1.0 - afBary[0] - afBary[2]; - } - else - { - akDiff[3] = *this - rkV2; - kTmp = akDiff[3].Cross(kE12); - afBary[0] = kE02cE12.Dot(kTmp)*fInvSqrArea; - kTmp = kE02.Cross(akDiff[3]); - afBary[1] = kE02cE12.Dot(kTmp)*fInvSqrArea; - afBary[2] = 1.0 - afBary[0] - afBary[1]; - afBary[3] = 0.0; - } - } - else - { - // The tetrahedron is potentially a sliver. Determine the edge of - // maximum length and compute barycentric coordinates with respect - // to that edge. - double fMaxSqrLength = akDiff[0].SquaredLength(); - iMaxIndex = 0; // <V0,V3> - double fSqrLength = akDiff[1].SquaredLength(); - - if( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 1; // <V1,V3> - fMaxSqrLength = fSqrLength; - } - fSqrLength = akDiff[2].SquaredLength(); - - if( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 2; // <V2,V3> - fMaxSqrLength = fSqrLength; - } - fSqrLength = kE02.SquaredLength(); - - if( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 3; // <V0,V2> - fMaxSqrLength = fSqrLength; - } - fSqrLength = kE12.SquaredLength(); - - if( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 4; // <V1,V2> - fMaxSqrLength = fSqrLength; - } - - Vector3D kE01 = rkV0 - rkV1; - fSqrLength = kE01.SquaredLength(); - - if( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 5; // <V0,V1> - fMaxSqrLength = fSqrLength; - } + if (UbMath::greater(fMaxSqrArea, 0.0)) { + double fInvSqrArea = 1.0 / fMaxSqrArea; + Vector3D kTmp; + if (iMaxIndex == 0) { + kTmp = akDiff[3].Cross(akDiff[1]); + afBary[0] = kE0cE1.Dot(kTmp) * fInvSqrArea; + kTmp = akDiff[0].Cross(akDiff[3]); + afBary[1] = kE0cE1.Dot(kTmp) * fInvSqrArea; + afBary[2] = 0.0; + afBary[3] = 1.0 - afBary[0] - afBary[1]; + } else if (iMaxIndex == 1) { + afBary[0] = 0.0; + kTmp = akDiff[3].Cross(akDiff[2]); + afBary[1] = kE1cE2.Dot(kTmp) * fInvSqrArea; + kTmp = akDiff[1].Cross(akDiff[3]); + afBary[2] = kE1cE2.Dot(kTmp) * fInvSqrArea; + afBary[3] = 1.0 - afBary[1] - afBary[2]; + } else if (iMaxIndex == 2) { + kTmp = akDiff[2].Cross(akDiff[3]); + afBary[0] = kE2cE0.Dot(kTmp) * fInvSqrArea; + afBary[1] = 0.0; + kTmp = akDiff[3].Cross(akDiff[0]); + afBary[2] = kE2cE0.Dot(kTmp) * fInvSqrArea; + afBary[3] = 1.0 - afBary[0] - afBary[2]; + } else { + akDiff[3] = *this - rkV2; + kTmp = akDiff[3].Cross(kE12); + afBary[0] = kE02cE12.Dot(kTmp) * fInvSqrArea; + kTmp = kE02.Cross(akDiff[3]); + afBary[1] = kE02cE12.Dot(kTmp) * fInvSqrArea; + afBary[2] = 1.0 - afBary[0] - afBary[1]; + afBary[3] = 0.0; + } + } else { + // The tetrahedron is potentially a sliver. Determine the edge of + // maximum length and compute barycentric coordinates with respect + // to that edge. + double fMaxSqrLength = akDiff[0].SquaredLength(); + iMaxIndex = 0; // <V0,V3> + double fSqrLength = akDiff[1].SquaredLength(); - if(UbMath::greater(fMaxSqrLength, 0.0) ) - { - double fInvSqrLength = 1.0/fMaxSqrLength; - if( iMaxIndex == 0 ) - { - // P-V3 = t*(V0-V3) - afBary[0] = akDiff[3].Dot(akDiff[0])*fInvSqrLength; - afBary[1] = 0.0; - afBary[2] = 0.0; - afBary[3] = 1.0 - afBary[0]; + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 1; // <V1,V3> + fMaxSqrLength = fSqrLength; } - else if( iMaxIndex == 1 ) - { - // P-V3 = t*(V1-V3) - afBary[0] = 0.0; - afBary[1] = akDiff[3].Dot(akDiff[1])*fInvSqrLength; - afBary[2] = 0.0; - afBary[3] = 1.0 - afBary[1]; + fSqrLength = akDiff[2].SquaredLength(); + + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 2; // <V2,V3> + fMaxSqrLength = fSqrLength; } - else if( iMaxIndex == 2 ) - { - // P-V3 = t*(V2-V3) - afBary[0] = 0.0; - afBary[1] = 0.0; - afBary[2] = akDiff[3].Dot(akDiff[2])*fInvSqrLength; - afBary[3] = 1.0 - afBary[2]; + fSqrLength = kE02.SquaredLength(); + + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 3; // <V0,V2> + fMaxSqrLength = fSqrLength; } - else if( iMaxIndex == 3 ) - { - // P-V2 = t*(V0-V2) - akDiff[3] = *this - rkV2; - afBary[0] = akDiff[3].Dot(kE02)*fInvSqrLength; - afBary[1] = 0.0; - afBary[2] = 1.0 - afBary[0]; - afBary[3] = 0.0; + fSqrLength = kE12.SquaredLength(); + + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 4; // <V1,V2> + fMaxSqrLength = fSqrLength; } - else if( iMaxIndex == 4 ) - { - // P-V2 = t*(V1-V2) - akDiff[3] = *this - rkV2; - afBary[0] = 0.0; - afBary[1] = akDiff[3].Dot(kE12)*fInvSqrLength; - afBary[2] = 1.0 - afBary[1]; - afBary[3] = 0.0; + + Vector3D kE01 = rkV0 - rkV1; + fSqrLength = kE01.SquaredLength(); + + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 5; // <V0,V1> + fMaxSqrLength = fSqrLength; } - else - { - // P-V1 = t*(V0-V1) - akDiff[3] = *this - rkV1; - afBary[0] = akDiff[3].Dot(kE01)*fInvSqrLength; - afBary[1] = 1.0 - afBary[0]; - afBary[2] = 0.0; - afBary[3] = 0.0; + + if (UbMath::greater(fMaxSqrLength, 0.0)) { + double fInvSqrLength = 1.0 / fMaxSqrLength; + if (iMaxIndex == 0) { + // P-V3 = t*(V0-V3) + afBary[0] = akDiff[3].Dot(akDiff[0]) * fInvSqrLength; + afBary[1] = 0.0; + afBary[2] = 0.0; + afBary[3] = 1.0 - afBary[0]; + } else if (iMaxIndex == 1) { + // P-V3 = t*(V1-V3) + afBary[0] = 0.0; + afBary[1] = akDiff[3].Dot(akDiff[1]) * fInvSqrLength; + afBary[2] = 0.0; + afBary[3] = 1.0 - afBary[1]; + } else if (iMaxIndex == 2) { + // P-V3 = t*(V2-V3) + afBary[0] = 0.0; + afBary[1] = 0.0; + afBary[2] = akDiff[3].Dot(akDiff[2]) * fInvSqrLength; + afBary[3] = 1.0 - afBary[2]; + } else if (iMaxIndex == 3) { + // P-V2 = t*(V0-V2) + akDiff[3] = *this - rkV2; + afBary[0] = akDiff[3].Dot(kE02) * fInvSqrLength; + afBary[1] = 0.0; + afBary[2] = 1.0 - afBary[0]; + afBary[3] = 0.0; + } else if (iMaxIndex == 4) { + // P-V2 = t*(V1-V2) + akDiff[3] = *this - rkV2; + afBary[0] = 0.0; + afBary[1] = akDiff[3].Dot(kE12) * fInvSqrLength; + afBary[2] = 1.0 - afBary[1]; + afBary[3] = 0.0; + } else { + // P-V1 = t*(V0-V1) + akDiff[3] = *this - rkV1; + afBary[0] = akDiff[3].Dot(kE01) * fInvSqrLength; + afBary[1] = 1.0 - afBary[0]; + afBary[2] = 0.0; + afBary[3] = 0.0; + } + } else { + // tetrahedron is a nearly a point, just return equal weights + afBary[0] = 0.25; + afBary[1] = afBary[0]; + afBary[2] = afBary[0]; + afBary[3] = afBary[0]; } - } - else - { - // tetrahedron is a nearly a point, just return equal weights - afBary[0] = 0.25; - afBary[1] = afBary[0]; - afBary[2] = afBary[0]; - afBary[3] = afBary[0]; - } - } - } + } + } } /*=======================================================*/ -void Vector3D::Orthonormalize(Vector3D& rkU, Vector3D& rkV, Vector3D& rkW) +void Vector3D::Orthonormalize(Vector3D &rkU, Vector3D &rkV, Vector3D &rkW) { - // If the input vectors are v0, v1, and v2, then the Gram-Schmidt - // orthonormalization produces vectors u0, u1, and u2 as follows, - // - // u0 = v0/|v0| - // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0| - // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1| - // - // where |A| indicates length of vector A and A*B indicates dot - // product of vectors A and B. + // If the input vectors are v0, v1, and v2, then the Gram-Schmidt + // orthonormalization produces vectors u0, u1, and u2 as follows, + // + // u0 = v0/|v0| + // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0| + // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1| + // + // where |A| indicates length of vector A and A*B indicates dot + // product of vectors A and B. - // compute u0 - rkU.Normalize(); + // compute u0 + rkU.Normalize(); - // compute u1 - double fDot0 = rkU.Dot(rkV); - rkV -= fDot0*rkU; - rkV.Normalize(); + // compute u1 + double fDot0 = rkU.Dot(rkV); + rkV -= fDot0 * rkU; + rkV.Normalize(); - // compute u2 - double fDot1 = rkV.Dot(rkW); - fDot0 = rkU.Dot(rkW); - rkW -= fDot0*rkU + fDot1*rkV; - rkW.Normalize(); + // compute u2 + double fDot1 = rkV.Dot(rkW); + fDot0 = rkU.Dot(rkW); + rkW -= fDot0 * rkU + fDot1 * rkV; + rkW.Normalize(); } /*=======================================================*/ -void Vector3D::Orthonormalize(Vector3D* akV) -{ - Orthonormalize(akV[0],akV[1],akV[2]); -} +void Vector3D::Orthonormalize(Vector3D *akV) { Orthonormalize(akV[0], akV[1], akV[2]); } /*=======================================================*/ -void Vector3D::GenerateOrthonormalBasis(Vector3D& rkU, Vector3D& rkV,Vector3D& rkW, bool bUnitLengthW) +void Vector3D::GenerateOrthonormalBasis(Vector3D &rkU, Vector3D &rkV, Vector3D &rkW, bool bUnitLengthW) { - if ( !bUnitLengthW ) - rkW.Normalize(); + if (!bUnitLengthW) + rkW.Normalize(); - double fInvLength; + double fInvLength; - if (UbMath::greaterEqual( std::fabs(rkW.m_afTuple[0]),std::fabs(rkW.m_afTuple[1]) ) ) - { - // W.x or W.z is the largest magnitude component, swap them - fInvLength = UbMath::invSqrt(rkW.m_afTuple[0]*rkW.m_afTuple[0] + rkW.m_afTuple[2]*rkW.m_afTuple[2]); - rkU.m_afTuple[0] = -rkW.m_afTuple[2]*fInvLength; - rkU.m_afTuple[1] = (double)0.0; - rkU.m_afTuple[2] = +rkW.m_afTuple[0]*fInvLength; - } - else - { - // W.y or W.z is the largest magnitude component, swap them - fInvLength = UbMath::invSqrt(rkW.m_afTuple[1]*rkW.m_afTuple[1] + rkW.m_afTuple[2]*rkW.m_afTuple[2]); - rkU.m_afTuple[0] = (double)0.0; - rkU.m_afTuple[1] = +rkW.m_afTuple[2]*fInvLength; - rkU.m_afTuple[2] = -rkW.m_afTuple[1]*fInvLength; - } + if (UbMath::greaterEqual(std::fabs(rkW.m_afTuple[0]), std::fabs(rkW.m_afTuple[1]))) { + // W.x or W.z is the largest magnitude component, swap them + fInvLength = UbMath::invSqrt(rkW.m_afTuple[0] * rkW.m_afTuple[0] + rkW.m_afTuple[2] * rkW.m_afTuple[2]); + rkU.m_afTuple[0] = -rkW.m_afTuple[2] * fInvLength; + rkU.m_afTuple[1] = (double)0.0; + rkU.m_afTuple[2] = +rkW.m_afTuple[0] * fInvLength; + } else { + // W.y or W.z is the largest magnitude component, swap them + fInvLength = UbMath::invSqrt(rkW.m_afTuple[1] * rkW.m_afTuple[1] + rkW.m_afTuple[2] * rkW.m_afTuple[2]); + rkU.m_afTuple[0] = (double)0.0; + rkU.m_afTuple[1] = +rkW.m_afTuple[2] * fInvLength; + rkU.m_afTuple[2] = -rkW.m_afTuple[1] * fInvLength; + } - rkV = rkW.Cross(rkU); + rkV = rkW.Cross(rkU); } /*=======================================================*/ -//globaler operator* -Vector3D operator*(const double& fScalar, const Vector3D& rkV) +// globaler operator* +Vector3D operator*(const double &fScalar, const Vector3D &rkV) { - return Vector3D( fScalar*rkV[0], - fScalar*rkV[1], - fScalar*rkV[2] ); + return Vector3D(fScalar * rkV[0], fScalar * rkV[1], fScalar * rkV[2]); } /*=======================================================*/ -std::ostream& operator<< (std::ostream& os, const Vector3D& rkV) +std::ostream &operator<<(std::ostream &os, const Vector3D &rkV) { - os<<rkV.toString(); - return os; + os << rkV.toString(); + return os; } diff --git a/src/basics/basics/utilities/Vector3D.h b/src/basics/basics/utilities/Vector3D.h index 03f47b033..b278a80d7 100644 --- a/src/basics/basics/utilities/Vector3D.h +++ b/src/basics/basics/utilities/Vector3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,102 +35,102 @@ #include <string> - class Vector3D - { - public: - // construction - Vector3D(); - Vector3D(const double& fX1, const double& fX2, const double& fX3); - Vector3D(const Vector3D& rkV); - - std::string toString() const; - - // coordinate access - operator const double*() const; - operator double*(); - double operator[](const int& i) const; - double& operator[](const int& i); - double X1() const; - double& X1(); - double X2() const; - double& X2(); - double X3() const; - double& X3(); - - // assignment - Vector3D& operator=(const Vector3D& rkV); - - // comparison - bool operator==(const Vector3D& rkV) const; - bool operator!=(const Vector3D& rkV) const; - bool operator< (const Vector3D& rkV) const; - bool operator<=(const Vector3D& rkV) const; - bool operator> (const Vector3D& rkV) const; - bool operator>=(const Vector3D& rkV) const; - - // arithmetic operations - Vector3D operator+(const Vector3D& rkV) const; - Vector3D operator-(const Vector3D& rkV) const; - Vector3D operator*(const double& fScalar) const; - Vector3D operator/(const double& fScalar) const; - Vector3D operator-() const; - - // arithmetic updates - Vector3D& operator+= (const Vector3D& rkV); - Vector3D& operator-= (const Vector3D& rkV); - Vector3D& operator*= (const double& fScalar); - Vector3D& operator/= (const double& fScalar); - - Vector3D Add(Vector3D& vector); - Vector3D Subtract(Vector3D& vector); - Vector3D Scale(const double& x); - - // vector operations - double Length () const; - double SquaredLength () const; - double Dot (const Vector3D& rkV) const; - double Normalize (); - - // The cross products are computed using the right-handed rule. Be aware - // that some graphics APIs use a left-handed rule. If you have to compute - // a cross product with these functions and send the result to the API - // that expects left-handed, you will need to change sign on the vector - // (replace each component value c by -c). - Vector3D Cross (const Vector3D& rkV) const; - Vector3D UnitCross (const Vector3D& rkV) const; - - // Compute the barycentric coordinates of the point with respect to the - // tetrahedron <V0,V1,V2,V3>, P = b0*V0 + b1*V1 + b2*V2 + b3*V3, where - // b0 + b1 + b2 + b3 = 1. - void GetBarycentrics (const Vector3D& rkV0, const Vector3D& rkV1, const Vector3D& rkV2, const Vector3D& rkV3, double afBary[4]) const; - - // Gram-Schmidt orthonormalization. Take linearly independent vectors - // U, V, and W and compute an orthonormal set (unit length, mutually - // perpendicular). - static void Orthonormalize (Vector3D& rkU, Vector3D& rkV, Vector3D& rkW); - static void Orthonormalize (Vector3D* akV); - - // Input W must be initialized to a nonzero vector, output is {U,V,W}, - // an orthonormal basis. A hint is provided about whether or not W - // is already unit length. - static void GenerateOrthonormalBasis (Vector3D& rkU, Vector3D& rkV, Vector3D& rkW, bool bUnitLengthW); - - // special vectors - static const Vector3D ZERO; - static const Vector3D UNIT_X1; - static const Vector3D UNIT_X2; - static const Vector3D UNIT_X3; - - protected: - // support for comparisons - int CompareArrays (const Vector3D& rkV) const; - - double m_afTuple[3]; - }; - - //globaler multiplaktor mit skalar - Vector3D operator*(const double& fScalar, const Vector3D& rkV); - std::ostream& operator<<(std::ostream& os, const Vector3D& rkV); - - +class Vector3D +{ +public: + // construction + Vector3D(); + Vector3D(const double &fX1, const double &fX2, const double &fX3); + Vector3D(const Vector3D &rkV); + + std::string toString() const; + + // coordinate access + operator const double *() const; + operator double *(); + double operator[](const int &i) const; + double &operator[](const int &i); + double X1() const; + double &X1(); + double X2() const; + double &X2(); + double X3() const; + double &X3(); + + // assignment + Vector3D &operator=(const Vector3D &rkV); + + // comparison + bool operator==(const Vector3D &rkV) const; + bool operator!=(const Vector3D &rkV) const; + bool operator<(const Vector3D &rkV) const; + bool operator<=(const Vector3D &rkV) const; + bool operator>(const Vector3D &rkV) const; + bool operator>=(const Vector3D &rkV) const; + + // arithmetic operations + Vector3D operator+(const Vector3D &rkV) const; + Vector3D operator-(const Vector3D &rkV) const; + Vector3D operator*(const double &fScalar) const; + Vector3D operator/(const double &fScalar) const; + Vector3D operator-() const; + + // arithmetic updates + Vector3D &operator+=(const Vector3D &rkV); + Vector3D &operator-=(const Vector3D &rkV); + Vector3D &operator*=(const double &fScalar); + Vector3D &operator/=(const double &fScalar); + + Vector3D Add(Vector3D &vector); + Vector3D Subtract(Vector3D &vector); + Vector3D Scale(const double &x); + + // vector operations + double Length() const; + double SquaredLength() const; + double Dot(const Vector3D &rkV) const; + double Normalize(); + + // The cross products are computed using the right-handed rule. Be aware + // that some graphics APIs use a left-handed rule. If you have to compute + // a cross product with these functions and send the result to the API + // that expects left-handed, you will need to change sign on the vector + // (replace each component value c by -c). + Vector3D Cross(const Vector3D &rkV) const; + Vector3D UnitCross(const Vector3D &rkV) const; + + // Compute the barycentric coordinates of the point with respect to the + // tetrahedron <V0,V1,V2,V3>, P = b0*V0 + b1*V1 + b2*V2 + b3*V3, where + // b0 + b1 + b2 + b3 = 1. + void GetBarycentrics(const Vector3D &rkV0, const Vector3D &rkV1, const Vector3D &rkV2, const Vector3D &rkV3, + double afBary[4]) const; + + // Gram-Schmidt orthonormalization. Take linearly independent vectors + // U, V, and W and compute an orthonormal set (unit length, mutually + // perpendicular). + static void Orthonormalize(Vector3D &rkU, Vector3D &rkV, Vector3D &rkW); + static void Orthonormalize(Vector3D *akV); + + // Input W must be initialized to a nonzero vector, output is {U,V,W}, + // an orthonormal basis. A hint is provided about whether or not W + // is already unit length. + static void GenerateOrthonormalBasis(Vector3D &rkU, Vector3D &rkV, Vector3D &rkW, bool bUnitLengthW); + + // special vectors + static const Vector3D ZERO; + static const Vector3D UNIT_X1; + static const Vector3D UNIT_X2; + static const Vector3D UNIT_X3; + +protected: + // support for comparisons + int CompareArrays(const Vector3D &rkV) const; + + double m_afTuple[3]; +}; + +// globaler multiplaktor mit skalar +Vector3D operator*(const double &fScalar, const Vector3D &rkV); +std::ostream &operator<<(std::ostream &os, const Vector3D &rkV); + #endif diff --git a/src/basics/basics/writer/WbWriter.h b/src/basics/basics/writer/WbWriter.h index 8e5524416..26d43464c 100644 --- a/src/basics/basics/writer/WbWriter.h +++ b/src/basics/basics/writer/WbWriter.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,13 +33,12 @@ #ifndef WBWRITER_H #define WBWRITER_H -#include <vector> -#include <string> #include <fstream> -#include <sstream> #include <iostream> #include <map> - +#include <sstream> +#include <string> +#include <vector> #include <basics/utilities/UbException.h> #include <basics/utilities/UbSystem.h> @@ -48,64 +47,133 @@ class WbWriter { public: - ////////////////////////////////////////////////////////////////////////// - virtual ~WbWriter() = default; + ////////////////////////////////////////////////////////////////////////// + virtual ~WbWriter() = default; - ////////////////////////////////////////////////////////////////////////// - //rein virtuelle Methoden - virtual std::string getFileExtension() = 0; + ////////////////////////////////////////////////////////////////////////// + // rein virtuelle Methoden + virtual std::string getFileExtension() = 0; - ////////////////////////////////////////////////////////////////////////// - //nodes - virtual std::string writeNodes(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeNodesWithNodeData(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector<std::string >& /*datanames*/, std::vector<std::vector<double > >& /*nodedata*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeNodesWithNodeDataDouble(const std::string& /*filename*/,std::vector< UbTupleDouble3 >& /*nodes*/, std::vector<std::string >& /*datanames*/, std::vector<std::vector<double > >& /*nodedata*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } + ////////////////////////////////////////////////////////////////////////// + // nodes + virtual std::string writeNodes(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeNodesWithNodeData(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<std::string> & /*datanames*/, + std::vector<std::vector<double>> & /*nodedata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeNodesWithNodeDataDouble(const std::string & /*filename*/, + std::vector<UbTupleDouble3> & /*nodes*/, + std::vector<std::string> & /*datanames*/, + std::vector<std::vector<double>> & /*nodedata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } - ////////////////////////////////////////////////////////////////////////// - //lines - // 0 ---- 1 - //nodenumbering must start with 0! - virtual std::string writeLines(const std::string& /*filename*/,std::vector<UbTupleFloat3 >& /*nodes*/, std::vector<UbTupleInt2 >& /*lines*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeLinesWithNodeData(const std::string& /*filename*/,std::vector<UbTupleFloat3 >& /*nodes*/, std::vector<UbTupleInt2 >& /*lines*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } + ////////////////////////////////////////////////////////////////////////// + // lines + // 0 ---- 1 + // nodenumbering must start with 0! + virtual std::string writeLines(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt2> & /*lines*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeLinesWithNodeData(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt2> & /*lines*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } - ////////////////////////////////////////////////////////////////////////// - //triangles - //cell numbering: - // 2 - // - // 0 === 1 - //nodenumbering must start with 0! - virtual std::string writeTriangles(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector< UbTupleInt3 >& /*cells*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeTrianglesWithNodeData(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector< UbTupleInt3 >& /*cells*/, std::vector<std::string >& /*datanames*/, std::vector<std::vector<double > >& /*nodedata*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } + ////////////////////////////////////////////////////////////////////////// + // triangles + // cell numbering: + // 2 + // + // 0 === 1 + // nodenumbering must start with 0! + virtual std::string writeTriangles(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt3> & /*cells*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeTrianglesWithNodeData(const std::string & /*filename*/, + std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt3> & /*cells*/, + std::vector<std::string> & /*datanames*/, + std::vector<std::vector<double>> & /*nodedata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } - ////////////////////////////////////////////////////////////////////////// - //quads - //cell numbering: - // 3---2 - // | | - // 0---1 - //nodenumbering must start with 0! - virtual std::string writeQuads(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector< UbTupleInt4 >& /*cells*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeQuadsWithNodeData(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector< UbTupleInt4 >& /*cells*/, std::vector< std::string >& /*datanames*/, std::vector< std::vector< double > >& /*nodedata*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeQuadsWithCellData(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector< UbTupleInt4 >& /*cells*/, std::vector< std::string >& /*datanames*/, std::vector< std::vector< double > >& /*celldata*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeQuadsWithNodeAndCellData(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector< UbTupleInt4 >& /*cells*/, - std::vector< std::string >& /*nodedatanames*/, std::vector< std::vector< double > >& /*nodedata*/, std::vector< std::string >& /*celldatanames*/, std::vector< std::vector< double > >& /*celldata*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } + ////////////////////////////////////////////////////////////////////////// + // quads + // cell numbering: + // 3---2 + // | | + // 0---1 + // nodenumbering must start with 0! + virtual std::string writeQuads(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt4> & /*cells*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeQuadsWithNodeData(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt4> & /*cells*/, + std::vector<std::string> & /*datanames*/, + std::vector<std::vector<double>> & /*nodedata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeQuadsWithCellData(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt4> & /*cells*/, + std::vector<std::string> & /*datanames*/, + std::vector<std::vector<double>> & /*celldata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeQuadsWithNodeAndCellData( + const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, std::vector<UbTupleInt4> & /*cells*/, + std::vector<std::string> & /*nodedatanames*/, std::vector<std::vector<double>> & /*nodedata*/, + std::vector<std::string> & /*celldatanames*/, std::vector<std::vector<double>> & /*celldata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } - ////////////////////////////////////////////////////////////////////////// - //octs - // 7 ---- 6 - // /| /| - // 4 +--- 5 | - // | | | | - // | 3 ---+ 2 - // |/ |/ - // 0 ---- 1 - virtual std::string writeOcts(const std::string& /*filename*/,std::vector< UbTupleFloat3 >& /*nodes*/, std::vector< UbTupleInt8 >& /*cells*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeOctsWithCellData(const std::string& /*filename*/,std::vector<UbTupleFloat3 >& /*nodes*/, std::vector<UbTupleInt8 >& /*cells*/, std::vector<std::string >& /*datanames*/, std::vector<std::vector<double > >& /*celldata*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual std::string writeOctsWithNodeData(const std::string& /*filename*/,std::vector<UbTupleFloat3 >& /*nodes*/, std::vector<UbTupleUInt8 >& /*cells*/, std::vector<std::string >& /*datanames*/, std::vector<std::vector<double > >& /*nodedata*/){ throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } + ////////////////////////////////////////////////////////////////////////// + // octs + // 7 ---- 6 + // /| /| + // 4 +--- 5 | + // | | | | + // | 3 ---+ 2 + // |/ |/ + // 0 ---- 1 + virtual std::string writeOcts(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt8> & /*cells*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeOctsWithCellData(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleInt8> & /*cells*/, + std::vector<std::string> & /*datanames*/, + std::vector<std::vector<double>> & /*celldata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual std::string writeOctsWithNodeData(const std::string & /*filename*/, std::vector<UbTupleFloat3> & /*nodes*/, + std::vector<UbTupleUInt8> & /*cells*/, + std::vector<std::string> & /*datanames*/, + std::vector<std::vector<double>> & /*nodedata*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } private: - }; -#endif //WBWRITER_H +#endif // WBWRITER_H diff --git a/src/basics/basics/writer/WbWriterVtkXmlASCII.cpp b/src/basics/basics/writer/WbWriterVtkXmlASCII.cpp index d4ad420ff..e217b5e24 100644 --- a/src/basics/basics/writer/WbWriterVtkXmlASCII.cpp +++ b/src/basics/basics/writer/WbWriterVtkXmlASCII.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,509 +30,543 @@ //! \ingroup writer //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#include <basics/writer/WbWriterVtkXmlASCII.h> #include <basics/utilities/UbLogger.h> +#include <basics/writer/WbWriterVtkXmlASCII.h> #include <cstring> #include <limits> using namespace std; /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::pvdEndTag =" </Collection>\n</VTKFile>"; +std::string WbWriterVtkXmlASCII::pvdEndTag = " </Collection>\n</VTKFile>"; /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeCollection(const std::string& filename, const std::vector<std::string>& filenames, const double& timeStep, const bool& sepGroups) +std::string WbWriterVtkXmlASCII::writeCollection(const std::string &filename, const std::vector<std::string> &filenames, + const double &timeStep, const bool &sepGroups) { - std::string vtkfilename=filename+".pvd"; - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - std::string endian; - if(UbSystem::isLittleEndian()) endian = "LittleEndian"; - else endian = "BigEndian"; - out<<"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\""<<endian<<"\" >\n"; - out<<" <Collection>"<<endl; - - int group = 0, part=0; - for(std::size_t i=0; i<filenames.size(); i++) - { - out<<" <DataSet timestep=\""<<timeStep<<"\" group=\""<<group<<"\" part=\""<<part<<"\" file=\""<<filenames[i]<<"\"/>\n"; - if(sepGroups) group++; - else part++; - } - out<<pvdEndTag; - out.close(); - - return vtkfilename; + std::string vtkfilename = filename + ".pvd"; + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + std::string endian; + if (UbSystem::isLittleEndian()) + endian = "LittleEndian"; + else + endian = "BigEndian"; + out << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << endian << "\" >\n"; + out << " <Collection>" << endl; + + int group = 0, part = 0; + for (std::size_t i = 0; i < filenames.size(); i++) { + out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << part + << "\" file=\"" << filenames[i] << "\"/>\n"; + if (sepGroups) + group++; + else + part++; + } + out << pvdEndTag; + out.close(); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::addFilesToCollection(const std::string& filename, const std::vector<std::string>& filenames, const double& timeStep, const bool& sepGroups) +std::string WbWriterVtkXmlASCII::addFilesToCollection(const std::string &filename, + const std::vector<std::string> &filenames, const double &timeStep, + const bool &sepGroups) { - std::string vtkfilename=filename; - std::fstream test(vtkfilename.c_str(), ios::in); - if(!test) - { - test.clear(); - vtkfilename += ".pvd"; - test.open(vtkfilename.c_str(), ios::in); - if(!test) return this->writeCollection(filename,filenames,timeStep,sepGroups); - } - - std::fstream out(vtkfilename.c_str(), ios::in | ios::out); - out.seekp(-(int)pvdEndTag.size()-1, ios_base::end); - - int group = 0; - for(std::size_t i=0; i<filenames.size(); i++) - { - out<<" <DataSet timestep=\""<<timeStep<<"\" group=\""<<group<<"\" part=\""<<i<<"\" file=\""<<filenames[i]<<"\"/>\n"; - if(sepGroups) group++; - } - out<<pvdEndTag; - - return vtkfilename; + std::string vtkfilename = filename; + std::fstream test(vtkfilename.c_str(), ios::in); + if (!test) { + test.clear(); + vtkfilename += ".pvd"; + test.open(vtkfilename.c_str(), ios::in); + if (!test) + return this->writeCollection(filename, filenames, timeStep, sepGroups); + } + + std::fstream out(vtkfilename.c_str(), ios::in | ios::out); + out.seekp(-(int)pvdEndTag.size() - 1, ios_base::end); + + int group = 0; + for (std::size_t i = 0; i < filenames.size(); i++) { + out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << i << "\" file=\"" + << filenames[i] << "\"/>\n"; + if (sepGroups) + group++; + } + out << pvdEndTag; + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeParallelFile(const string& filename,vector<string>& pieceSources, vector<string>& pointDataNames, vector<string>& cellDataNames) +std::string WbWriterVtkXmlASCII::writeParallelFile(const string &filename, vector<string> &pieceSources, + vector<string> &pointDataNames, vector<string> &cellDataNames) { - string vtkfilename=filename+".pvtu"; - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeParallelFile to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - //VTK FILE - out<<"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n"; - out<<" <PUnstructuredGrid GhostLevel=\"0\">\n"; - out<<" <PPoints>\n"; - out<<" <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n"; - out<<" </PPoints>\n"; - out<<" <PPointData>\n"; - for(size_t s=0; s<pointDataNames.size(); s++) - out<< " <PDataArray type=\"Float64\" Name=\""<< pointDataNames[s] <<"\"/>\n"; - out<<" </PPointData>\n"; - if (cellDataNames.size() > 0) - { - out<<" <PCellData>\n"; - for(size_t s=0; s<cellDataNames.size(); s++) - out<< " <PDataArray type=\"Float32\" Name=\""<< cellDataNames[s] <<"\"/>\n"; - out<<" </PCellData>\n"; - } - - for(size_t s=0; s<pieceSources.size(); s++) - out<<" <Piece Source=\""<<pieceSources[s]<<"\"/>\n"; - out<<" </PUnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeParallelFile to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + ".pvtu"; + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeParallelFile to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + // VTK FILE + out << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n"; + out << " <PUnstructuredGrid GhostLevel=\"0\">\n"; + out << " <PPoints>\n"; + out << " <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n"; + out << " </PPoints>\n"; + out << " <PPointData>\n"; + for (size_t s = 0; s < pointDataNames.size(); s++) + out << " <PDataArray type=\"Float64\" Name=\"" << pointDataNames[s] << "\"/>\n"; + out << " </PPointData>\n"; + if (cellDataNames.size() > 0) { + out << " <PCellData>\n"; + for (size_t s = 0; s < cellDataNames.size(); s++) + out << " <PDataArray type=\"Float32\" Name=\"" << cellDataNames[s] << "\"/>\n"; + out << " </PCellData>\n"; + } + + for (size_t s = 0; s < pieceSources.size(); s++) + out << " <Piece Source=\"" << pieceSources[s] << "\"/>\n"; + out << " </PUnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeParallelFile to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeQuads(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells) +std::string WbWriterVtkXmlASCII::writeQuads(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuads to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" " - << val<2>(cells[c]) <<" " - << val<4>(cells[c]) <<" " - << val<3>(cells[c]) <<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; - for(int c=1; c<nofCells+1; c++) - out<<c*4<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; - - for(int c=0; c<nofCells; c++) - out<<"8 "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Cells>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuads to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuads to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) + << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; + for (int c = 1; c < nofCells + 1; c++) + out << c * 4 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; + + for (int c = 0; c < nofCells; c++) + out << "8 "; + out << "\n"; + out << " </DataArray>\n"; + out << " </Cells>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuads to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeQuadsWithNodeData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells, vector< string >& datanames, vector< vector< double > >& nodedata) +std::string WbWriterVtkXmlASCII::writeQuadsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells, vector<string> &datanames, + vector<vector<double>> &nodedata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuadsWithNodeData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" " - << val<2>(cells[c]) <<" " - << val<4>(cells[c]) <<" " - << val<3>(cells[c]) <<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofCells+1; c++) - out<<c*4<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<<"8 "; - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - //write data section - out<<" <PointData Scalars=\"Scalars\"> \n"; - for(int s=0; s<(int)datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)nodedata[s].size(); d++) - out<<nodedata[s][d]<<" "; - - out<<"\n </DataArray>\n"; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) + << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofCells + 1; c++) + out << c * 4 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << "8 "; + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write data section + out << " <PointData Scalars=\"Scalars\"> \n"; + for (int s = 0; s < (int)datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)nodedata[s].size(); d++) + out << nodedata[s][d] << " "; + + out << "\n </DataArray>\n"; } - out<<" </PointData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuadsWithNodeData to "<<vtkfilename<<" - end"); - return vtkfilename; + out << " </PointData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeData to " << vtkfilename << " - end"); + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeQuadsWithCellData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells, vector< string >& datanames, vector< vector< double > >& celldata) +std::string WbWriterVtkXmlASCII::writeQuadsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells, vector<string> &datanames, + vector<vector<double>> &celldata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuadsWithCellData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" " - << val<2>(cells[c]) <<" " - << val<4>(cells[c]) <<" " - << val<3>(cells[c]) <<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofCells+1; c++) - out<<c*4<<" " ; - - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<<"8 "; - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - //write data section - out<<" <CellData Scalars=\"Scalars\"> \n"; - for(int s=0; s<(int)datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)celldata[s].size(); d++) - out<<celldata[s][d]<<" "; - - out<<"\n </DataArray>\n"; - } - out<<" </CellData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - - out.close(); - - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuadsWithCellData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithCellData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) + << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofCells + 1; c++) + out << c * 4 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << "8 "; + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write data section + out << " <CellData Scalars=\"Scalars\"> \n"; + for (int s = 0; s < (int)datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)celldata[s].size(); d++) + out << celldata[s][d] << " "; + + out << "\n </DataArray>\n"; + } + out << " </CellData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + + out.close(); + + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithCellData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells, - vector< string >& nodedatanames, vector< vector< double > >& nodedata, vector< string >& celldatanames, - vector< vector< double > >& celldata ) +string WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells, vector<string> &nodedatanames, + vector<vector<double>> &nodedata, + vector<string> &celldatanames, + vector<vector<double>> &celldata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" " - << val<2>(cells[c]) <<" " - << val<4>(cells[c]) <<" " - << val<3>(cells[c]) <<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofCells+1; c++) - out<<c*4<<" " ; - - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<<"8 "; - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - //write PointData section - out<<" <PointData Scalars=\"PScalars\"> \n"; - for(int s=0; s<(int)nodedatanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< nodedatanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)nodedata[s].size(); d++) - out<<nodedata[s][d]<<" "; - - out<<"\n </DataArray>\n"; - } - out<<" </PointData>\n"; - - //write celldata section - out<<" <CellData Scalars=\"CScalars\"> \n"; - for(int s=0; s<(int)celldatanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< celldatanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)celldata[s].size(); d++) - out<<celldata[s][d]<<" "; - - out<<"\n </DataArray>\n"; - } - out<<" </CellData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) + << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofCells + 1; c++) + out << c * 4 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << "8 "; + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write PointData section + out << " <PointData Scalars=\"PScalars\"> \n"; + for (int s = 0; s < (int)nodedatanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << nodedatanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)nodedata[s].size(); d++) + out << nodedata[s][d] << " "; + + out << "\n </DataArray>\n"; + } + out << " </PointData>\n"; + + // write celldata section + out << " <CellData Scalars=\"CScalars\"> \n"; + for (int s = 0; s < (int)celldatanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << celldatanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)celldata[s].size(); d++) + out << celldata[s][d] << " "; + + out << "\n </DataArray>\n"; + } + out << " </CellData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeQuadsWithNodeAndCellData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeLines(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleInt2 >& lines) +std::string WbWriterVtkXmlASCII::writeLines(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt2> &lines) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeLines to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofLines = (int)lines.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofLines<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; - - for(int c=0; c<nofLines; c++) - out<< val<1>(lines[c]) <<" "<< val<2>(lines[c])<<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; - for(int c=1; c<=nofLines; c++) - out<<c*2<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; - - for(int c=0; c<nofLines; c++) - out<<"3 "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Cells>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeLines to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofLines = (int)lines.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofLines << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; + + for (int c = 0; c < nofLines; c++) + out << val<1>(lines[c]) << " " << val<2>(lines[c]) << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; + for (int c = 1; c <= nofLines; c++) + out << c * 2 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; + + for (int c = 0; c < nofLines; c++) + out << "3 "; + out << "\n"; + out << " </DataArray>\n"; + out << " </Cells>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -//std::string WbWriterVtkXmlASCII::writeLinesWithNodeData(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) +// std::string WbWriterVtkXmlASCII::writeLinesWithNodeData(const string& filename,vector<UbTupleFloat3 >& nodes, +// vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) //{ // string vtkfilename=filename+getFileExtension(); // UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeLinesWithNodeData to "<<vtkfilename<<" - start"); @@ -609,613 +643,645 @@ std::string WbWriterVtkXmlASCII::writeLines(const string& filename,vector<UbTupl // return vtkfilename; //} /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeTriangles(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleInt3 >& triangles) +std::string WbWriterVtkXmlASCII::writeTriangles(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt3> &triangles) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeTriangles to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofTriangles= (int)triangles.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofTriangles<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; - - for(int c=0; c<nofTriangles; c++) - out<< val<1>(triangles[c]) <<" "<< val<2>(triangles[c])<<" "<< val<3>(triangles[c])<<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; - for(int c=1; c<nofTriangles+1; c++) - out<<c*3<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; - - for(int c=0; c<nofTriangles; c++) - out<<"5 "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Cells>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeTriangles to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTriangles to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofTriangles = (int)triangles.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofTriangles << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; + + for (int c = 0; c < nofTriangles; c++) + out << val<1>(triangles[c]) << " " << val<2>(triangles[c]) << " " << val<3>(triangles[c]) << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; + for (int c = 1; c < nofTriangles + 1; c++) + out << c * 3 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; + + for (int c = 0; c < nofTriangles; c++) + out << "5 "; + out << "\n"; + out << " </DataArray>\n"; + out << " </Cells>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTriangles to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeTrianglesWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt3 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) +std::string WbWriterVtkXmlASCII::writeTrianglesWithNodeData(const std::string &filename, + std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt3> &cells, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeTrianglesWithNodeData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" "<< val<2>(cells[c]) <<" "<< val<3>(cells[c]) <<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofCells+1; c++) - out<<c*3<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<<"5 "; - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - //write data section - out<<" <PointData Scalars=\"Scalars\"> \n"; - for(int s=0; s<(int)datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)nodedata[s].size(); d++) - out<<nodedata[s][d]<<" "; - - out<<"\n </DataArray>\n"; - } - out<<" </PointData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeTrianglesWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTrianglesWithNodeData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<3>(cells[c]) << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofCells + 1; c++) + out << c * 3 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << "5 "; + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write data section + out << " <PointData Scalars=\"Scalars\"> \n"; + for (int s = 0; s < (int)datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)nodedata[s].size(); d++) + out << nodedata[s][d] << " "; + + out << "\n </DataArray>\n"; + } + out << " </PointData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeTrianglesWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeOctsWithCellData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt8 >& cells, vector< string >& datanames, vector< vector< double > >& celldata) +std::string WbWriterVtkXmlASCII::writeOctsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt8> &cells, vector<string> &datanames, + vector<vector<double>> &celldata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeOctsWithCellData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" " - << val<2>(cells[c]) <<" " - << val<4>(cells[c]) <<" " - << val<3>(cells[c]) <<" " - << val<5>(cells[c]) <<" " - << val<6>(cells[c]) <<" " - << val<8>(cells[c]) <<" " - << val<7>(cells[c]) <<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofCells+1; c++) - out<<c*8<<" " ; - - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<<"11 "; - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - - //write data section - out<<" <CellData Scalars=\"Scalars\"> \n"; - for(int s=0; s<(int)datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)celldata[s].size(); d++) - out<<celldata[s][d]<<" "; - - out<<"\n </DataArray>\n"; - } - out<<" </CellData>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeOctsWithCellData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithCellData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) << " " + << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c]) + << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofCells + 1; c++) + out << c * 8 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << "11 "; + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write data section + out << " <CellData Scalars=\"Scalars\"> \n"; + for (int s = 0; s < (int)datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)celldata[s].size(); d++) + out << celldata[s][d] << " "; + + out << "\n </DataArray>\n"; + } + out << " </CellData>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithCellData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeOctsWithNodeData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleUInt8 >& cells, vector< string >& datanames, vector< vector< double > >& nodedata) +std::string WbWriterVtkXmlASCII::writeOctsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleUInt8> &cells, vector<string> &datanames, + vector<vector<double>> &nodedata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeOctsWithNodeData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<<val<1>(nodes[n])<<" "<<val<2>(nodes[n])<<" "<<val<3>(nodes[n])<<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" " - << val<2>(cells[c]) <<" " - << val<4>(cells[c]) <<" " - << val<3>(cells[c]) <<" " - << val<5>(cells[c]) <<" " - << val<6>(cells[c]) <<" " - << val<8>(cells[c]) <<" " - << val<7>(cells[c]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofCells+1; c++) - out<<c*8<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<<"11 "; - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - //write PointData section - out<<" <PointData Scalars=\"PScalars\"> \n"; - for(int s=0; s<(int)datanames.size(); ++s) - { - out<< " <DataArray type=\"Float64\" Name=\""<< datanames[s] <<"\" format=\"ascii\">"; - - for(int d=0; d<(int)nodedata[s].size(); d++) - { - //out<<base64_encode((unsigned char*)(&nodedata[s][d]),sizeof(float)); - //out.write((char*)&nodedata[s][d],sizeof(float)); - out<<nodedata[s][d]<<" "; - } - out<<"</DataArray>\n"; - } - out<<" </PointData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeOctsWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithNodeData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) << " " + << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c]) + << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofCells + 1; c++) + out << c * 8 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << "11 "; + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write PointData section + out << " <PointData Scalars=\"PScalars\"> \n"; + for (int s = 0; s < (int)datanames.size(); ++s) { + out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"ascii\">"; + + for (int d = 0; d < (int)nodedata[s].size(); d++) { + // out<<base64_encode((unsigned char*)(&nodedata[s][d]),sizeof(float)); + // out.write((char*)&nodedata[s][d],sizeof(float)); + out << nodedata[s][d] << " "; + } + out << "</DataArray>\n"; + } + out << " </PointData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOctsWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -std::string WbWriterVtkXmlASCII::writeOcts(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt8 >& cells) +std::string WbWriterVtkXmlASCII::writeOcts(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt8> &cells) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeOcts to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<< val<1>(cells[c]) <<" " - << val<2>(cells[c]) <<" " - << val<4>(cells[c]) <<" " - << val<3>(cells[c]) <<" " - << val<5>(cells[c]) <<" " - << val<6>(cells[c]) <<" " - << val<8>(cells[c]) <<" " - << val<7>(cells[c]) <<" "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofCells+1; c++) - out<<c*8<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - - for(int c=0; c<nofCells; c++) - out<<"11 "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Cells>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeOcts to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOcts to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << val<1>(cells[c]) << " " << val<2>(cells[c]) << " " << val<4>(cells[c]) << " " << val<3>(cells[c]) << " " + << val<5>(cells[c]) << " " << val<6>(cells[c]) << " " << val<8>(cells[c]) << " " << val<7>(cells[c]) + << " "; + out << "\n"; + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofCells + 1; c++) + out << c * 8 << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + + for (int c = 0; c < nofCells; c++) + out << "11 "; + out << "\n"; + out << " </DataArray>\n"; + out << " </Cells>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeOcts to " << vtkfilename << " - end"); + + return vtkfilename; } -std::string WbWriterVtkXmlASCII::writeNodes(const std::string& filename,std::vector< UbTupleFloat3 >& nodes) +std::string WbWriterVtkXmlASCII::writeNodes(const std::string &filename, std::vector<UbTupleFloat3> &nodes) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeLines to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofNodes<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; - for(int n=0; n<nofNodes; n++) - out<< n << " "; - out<<"\n"; - - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; - for(int n=1; n<=nofNodes; n++) - out << n << " "; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; - - for(int n=0; n<nofNodes; n++) - out<<"1 "; - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Cells>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeLines to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n"; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n"; + for (int n = 0; n < nofNodes; n++) + out << n << " "; + out << "\n"; + + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n"; + for (int n = 1; n <= nofNodes; n++) + out << n << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n"; + + for (int n = 0; n < nofNodes; n++) + out << "1 "; + out << "\n"; + out << " </DataArray>\n"; + out << " </Cells>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeLines to " << vtkfilename << " - end"); + + return vtkfilename; } -std::string WbWriterVtkXmlASCII::writeNodesWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) +std::string WbWriterVtkXmlASCII::writeNodesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeNodesWithNodeData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofNodes<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofNodes; c++) - out << c <<" "; - out<<"\n"; - - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofNodes+1; c++) - out<<c<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - for(int c=0; c<nofNodes; c++) - out<<"1 "; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - //write data section - out<<" <PointData Scalars=\"Scalars\"> \n"; - for(int s=0; s<(int)datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)nodedata[s].size(); d++) - out<<nodedata[s][d]<<" "; - - out<<"\n </DataArray>\n"; - } - out<<" </PointData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeNodesWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofNodes; c++) + out << c << " "; + out << "\n"; + + out << " </DataArray>\n"; + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofNodes + 1; c++) + out << c << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + for (int c = 0; c < nofNodes; c++) + out << "1 "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write data section + out << " <PointData Scalars=\"Scalars\"> \n"; + for (int s = 0; s < (int)datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)nodedata[s].size(); d++) + out << nodedata[s][d] << " "; + + out << "\n </DataArray>\n"; + } + out << " </PointData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } ////////////////////////////////////////////////////////////////////////// -std::string WbWriterVtkXmlASCII::writeNodesWithNodeDataDouble(const std::string& filename,std::vector< UbTupleDouble3 >& nodes, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) +std::string WbWriterVtkXmlASCII::writeNodesWithNodeDataDouble(const std::string &filename, + std::vector<UbTupleDouble3> &nodes, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) { - string vtkfilename=filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeNodesWithNodeData to "<<vtkfilename<<" - start"); - - std::ofstream out(vtkfilename.c_str()); - out.precision (std::numeric_limits<double>::digits10 + 1); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){UbSystem::makeDirectory(path);out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - - //VTK FILE - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofNodes<<"\"> \n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n "; - for(int n=0; n<nofNodes; n++) - out<< val<1>(nodes[n]) <<" "<< val<2>(nodes[n]) <<" "<< val<3>(nodes[n]) <<" "; - - out<<"\n"; - out<<" </DataArray>\n"; - out<<" </Points>\n"; - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; - - for(int c=0; c<nofNodes; c++) - out << c <<" "; - out<<"\n"; - - out<<" </DataArray>\n"; - out<<" <DataArray type=\"Int64\" Name=\"offsets\" format=\"ascii\">\n "; - for(int c=1; c<nofNodes+1; c++) - out<<c<<" " ; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; - for(int c=0; c<nofNodes; c++) - out<<"1 "; - - out<<"\n"; - out<<" </DataArray>\n"; - - out<<" </Cells>\n"; - - //write data section - out<<" <PointData Scalars=\"Scalars\"> \n"; - for(int s=0; s<(int)datanames.size(); ++s) - { - out<< " <DataArray type=\"Float64\" Name=\""<< datanames[s] <<"\" format=\"ascii\"> \n"; - - for(int d=0; d<(int)nodedata[s].size(); d++) - out<<nodedata[s][d]<<" "; - - out<<"\n </DataArray>\n"; - } - out<<" </PointData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlASCII::writeNodesWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - start"); + + std::ofstream out(vtkfilename.c_str()); + out.precision(std::numeric_limits<double>::digits10 + 1); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + + // VTK FILE + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\"> \n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n "; + for (int n = 0; n < nofNodes; n++) + out << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << " "; + + out << "\n"; + out << " </DataArray>\n"; + out << " </Points>\n"; + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n "; + + for (int c = 0; c < nofNodes; c++) + out << c << " "; + out << "\n"; + + out << " </DataArray>\n"; + out << " <DataArray type=\"Int64\" Name=\"offsets\" format=\"ascii\">\n "; + for (int c = 1; c < nofNodes + 1; c++) + out << c << " "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n "; + for (int c = 0; c < nofNodes; c++) + out << "1 "; + + out << "\n"; + out << " </DataArray>\n"; + + out << " </Cells>\n"; + + // write data section + out << " <PointData Scalars=\"Scalars\"> \n"; + for (int s = 0; s < (int)datanames.size(); ++s) { + out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"ascii\"> \n"; + + for (int d = 0; d < (int)nodedata[s].size(); d++) + out << nodedata[s][d] << " "; + + out << "\n </DataArray>\n"; + } + out << " </PointData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlASCII::writeNodesWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } diff --git a/src/basics/basics/writer/WbWriterVtkXmlASCII.h b/src/basics/basics/writer/WbWriterVtkXmlASCII.h index 11b557287..ac031f2ff 100644 --- a/src/basics/basics/writer/WbWriterVtkXmlASCII.h +++ b/src/basics/basics/writer/WbWriterVtkXmlASCII.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -37,89 +37,117 @@ #include <basics/writer/WbWriter.h> -class WbWriterVtkXmlASCII : public WbWriter +class WbWriterVtkXmlASCII : public WbWriter { public: - static WbWriterVtkXmlASCII* getInstance() - { - static WbWriterVtkXmlASCII instance; - return &instance; - } + static WbWriterVtkXmlASCII *getInstance() + { + static WbWriterVtkXmlASCII instance; + return &instance; + } - WbWriterVtkXmlASCII( const WbWriterVtkXmlASCII& ) = delete; - const WbWriterVtkXmlASCII& operator=( const WbWriterVtkXmlASCII& ) = delete; + WbWriterVtkXmlASCII(const WbWriterVtkXmlASCII &) = delete; + const WbWriterVtkXmlASCII &operator=(const WbWriterVtkXmlASCII &) = delete; private: - WbWriterVtkXmlASCII() : WbWriter() - { - if(sizeof(unsigned char)!=1) throw UbException(UB_EXARGS,"error char type mismatch"); - if(sizeof(int) !=4) throw UbException(UB_EXARGS,"error int type mismatch"); - if(sizeof(float) !=4) throw UbException(UB_EXARGS,"error float type mismatch"); - } - - static std::string pvdEndTag; + WbWriterVtkXmlASCII() : WbWriter() + { + if (sizeof(unsigned char) != 1) + throw UbException(UB_EXARGS, "error char type mismatch"); + if (sizeof(int) != 4) + throw UbException(UB_EXARGS, "error int type mismatch"); + if (sizeof(float) != 4) + throw UbException(UB_EXARGS, "error float type mismatch"); + } + + static std::string pvdEndTag; public: - std::string getFileExtension() override { return ".ascii.vtu"; } - - //write a metafile - std::string writeCollection(const std::string& filename, const std::vector<std::string>& filenames, const double& timesteps, const bool& sepGroups);//std::vector<double>& groups, std::vector<double>& parts); - std::string addFilesToCollection(const std::string& filename, const std::vector<std::string>& filenames, const double& timestep, const bool& sepGroups); - std::string writeParallelFile(const std::string& filename,std::vector<std::string>& pieceSources, std::vector<std::string>& pointDataNames, std::vector<std::string>& cellDataNames); - - ////////////////////////////////////////////////////////////////////////// - //nodes - std::string writeNodes(const std::string& filename,std::vector< UbTupleFloat3 >& nodes) override; - std::string writeNodesWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) override; - std::string writeNodesWithNodeDataDouble(const std::string& filename,std::vector< UbTupleDouble3 >& nodes, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) override; - - ////////////////////////////////////////////////////////////////////////// - //lines - // 0 ---- 1 - //nodenumbering must start with 0! - std::string writeLines(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt2 >& lines) override; - //std::string writeLinesWithNodeData(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata); - //FIXME: hides function in base class - - ////////////////////////////////////////////////////////////////////////// - //triangles - // 2 - // - // 0---1 - //nodenumbering must start with 0! - std::string writeTriangles(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt3 >& triangles) override; - std::string writeTrianglesWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt3 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) override; - - ////////////////////////////////////////////////////////////////////////// - //2D - //cell numbering: - // 3---2 - // | | - // 0---1 - //nodenumbering must start with 0! - - std::string writeQuads(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells) override; - std::string writeQuadsWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) override; - std::string writeQuadsWithCellData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& celldata) override; - std::string writeQuadsWithNodeAndCellData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells, - std::vector< std::string >& nodedatanames, std::vector< std::vector< double > >& nodedata, std::vector< std::string >& celldatanames, - std::vector< std::vector< double > >& celldata) override; - - ////////////////////////////////////////////////////////////////////////// - //octs - // 7 ---- 6 - // /| /| - // 4 +--- 5 | - // | | | | - // | 3 ---+ 2 - // |/ |/ - // 0 ---- 1 - std::string writeOcts(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt8 >& cells) override; - std::string writeOctsWithCellData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt8 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& celldata) override; - std::string writeOctsWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleUInt8 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) override; + std::string getFileExtension() override { return ".ascii.vtu"; } + + // write a metafile + std::string writeCollection(const std::string &filename, const std::vector<std::string> &filenames, + const double ×teps, + const bool &sepGroups); // std::vector<double>& groups, std::vector<double>& parts); + std::string addFilesToCollection(const std::string &filename, const std::vector<std::string> &filenames, + const double ×tep, const bool &sepGroups); + std::string writeParallelFile(const std::string &filename, std::vector<std::string> &pieceSources, + std::vector<std::string> &pointDataNames, std::vector<std::string> &cellDataNames); + + ////////////////////////////////////////////////////////////////////////// + // nodes + std::string writeNodes(const std::string &filename, std::vector<UbTupleFloat3> &nodes) override; + std::string writeNodesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + std::string writeNodesWithNodeDataDouble(const std::string &filename, std::vector<UbTupleDouble3> &nodes, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + + ////////////////////////////////////////////////////////////////////////// + // lines + // 0 ---- 1 + // nodenumbering must start with 0! + std::string writeLines(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt2> &lines) override; + // std::string writeLinesWithNodeData(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, + // std::vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& + // nodedata); + // FIXME: hides function in base class + + ////////////////////////////////////////////////////////////////////////// + // triangles + // 2 + // + // 0---1 + // nodenumbering must start with 0! + std::string writeTriangles(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt3> &triangles) override; + std::string writeTrianglesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt3> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + + ////////////////////////////////////////////////////////////////////////// + // 2D + // cell numbering: + // 3---2 + // | | + // 0---1 + // nodenumbering must start with 0! + + std::string writeQuads(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells) override; + std::string writeQuadsWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + std::string writeQuadsWithCellData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &celldata) override; + std::string writeQuadsWithNodeAndCellData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells, std::vector<std::string> &nodedatanames, + std::vector<std::vector<double>> &nodedata, + std::vector<std::string> &celldatanames, + std::vector<std::vector<double>> &celldata) override; + + ////////////////////////////////////////////////////////////////////////// + // octs + // 7 ---- 6 + // /| /| + // 4 +--- 5 | + // | | | | + // | 3 ---+ 2 + // |/ |/ + // 0 ---- 1 + std::string writeOcts(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt8> &cells) override; + std::string writeOctsWithCellData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt8> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &celldata) override; + std::string writeOctsWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleUInt8> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; private: - }; -#endif //WBWRITERVTKXMLASCII_H +#endif // WBWRITERVTKXMLASCII_H diff --git a/src/basics/basics/writer/WbWriterVtkXmlBinary.cpp b/src/basics/basics/writer/WbWriterVtkXmlBinary.cpp index d88459eb5..6731fa560 100644 --- a/src/basics/basics/writer/WbWriterVtkXmlBinary.cpp +++ b/src/basics/basics/writer/WbWriterVtkXmlBinary.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,214 +30,234 @@ //! \ingroup writer //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#include <basics/writer/WbWriterVtkXmlBinary.h> -#include <basics/writer/WbWriterVtkXmlASCII.h> #include <basics/utilities/UbLogger.h> +#include <basics/writer/WbWriterVtkXmlASCII.h> +#include <basics/writer/WbWriterVtkXmlBinary.h> #include <cstring> using namespace std; /*===============================================================================*/ -const std::string WbWriterVtkXmlBinary::pvdEndTag =" </Collection>\n</VTKFile>"; +const std::string WbWriterVtkXmlBinary::pvdEndTag = " </Collection>\n</VTKFile>"; /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeCollection(const string& filename, const vector<string>& filenames, const double& timeStep, const bool& sepGroups) +string WbWriterVtkXmlBinary::writeCollection(const string &filename, const vector<string> &filenames, + const double &timeStep, const bool &sepGroups) { - string vtkfilename=filename+".pvd"; - ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - string endian; - if(UbSystem::isLittleEndian()) endian = "LittleEndian"; - else endian = "BigEndian"; - out<<"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\""<<endian<<"\" >"<<endl; - out<<" <Collection>"<<endl; - - int group = 0, part=0; - for(size_t i=0; i<filenames.size(); i++) - { - out<<" <DataSet timestep=\""<<timeStep<<"\" group=\""<<group<<"\" part=\""<<part<<"\" file=\""<<filenames[i]<<"\"/>"<<endl; - if(sepGroups) group++; - else part++; - } - out<<pvdEndTag; - out.close(); - - return vtkfilename; + string vtkfilename = filename + ".pvd"; + ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + string endian; + if (UbSystem::isLittleEndian()) + endian = "LittleEndian"; + else + endian = "BigEndian"; + out << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << endian << "\" >" << endl; + out << " <Collection>" << endl; + + int group = 0, part = 0; + for (size_t i = 0; i < filenames.size(); i++) { + out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << part + << "\" file=\"" << filenames[i] << "\"/>" << endl; + if (sepGroups) + group++; + else + part++; + } + out << pvdEndTag; + out.close(); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::addFilesToCollection(const string& filename, const vector<string>& filenames, const double& timeStep, const bool& sepGroups) +string WbWriterVtkXmlBinary::addFilesToCollection(const string &filename, const vector<string> &filenames, + const double &timeStep, const bool &sepGroups) { - string vtkfilename=filename; - fstream test(vtkfilename.c_str(), ios::in); - if(!test) - { - test.clear(); - vtkfilename += ".pvd"; - test.open(vtkfilename.c_str(), ios::in); - if(!test) return this->writeCollection(filename,filenames,timeStep,sepGroups); - } - - fstream out(vtkfilename.c_str(), ios::in | ios::out); - out.seekp(-(int)pvdEndTag.size()-1, ios_base::end); - - int group = 0; - for(size_t i=0; i<filenames.size(); i++) - { - out<<" <DataSet timestep=\""<<timeStep<<"\" group=\""<<group<<"\" part=\""<<i<<"\" file=\""<<filenames[i]<<"\"/>"<<endl; - if(sepGroups) group++; - } - out<<pvdEndTag; - - return vtkfilename; + string vtkfilename = filename; + fstream test(vtkfilename.c_str(), ios::in); + if (!test) { + test.clear(); + vtkfilename += ".pvd"; + test.open(vtkfilename.c_str(), ios::in); + if (!test) + return this->writeCollection(filename, filenames, timeStep, sepGroups); + } + + fstream out(vtkfilename.c_str(), ios::in | ios::out); + out.seekp(-(int)pvdEndTag.size() - 1, ios_base::end); + + int group = 0; + for (size_t i = 0; i < filenames.size(); i++) { + out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << i << "\" file=\"" + << filenames[i] << "\"/>" << endl; + if (sepGroups) + group++; + } + out << pvdEndTag; + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeParallelFile(const string& filename,vector<string>& pieceSources, vector<string>& pointDataNames, vector<string>& cellDataNames) +string WbWriterVtkXmlBinary::writeParallelFile(const string &filename, vector<string> &pieceSources, + vector<string> &pointDataNames, vector<string> &cellDataNames) { - string vtkfilename=filename+".pvtu"; - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeParallelFile to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str()); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str());} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - //VTK FILE - out<<"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">"<<"\n"; - out<<" <PUnstructuredGrid GhostLevel=\"0\">"<<"\n"; - out<<" <PPoints>\n"; - out<<" <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n"; - out<<" </PPoints>\n"; - out<<" <PPointData>\n"; - for(size_t s=0; s<pointDataNames.size(); s++) - out<< " <PDataArray type=\"Float32\" Name=\""<< pointDataNames[s] <<"\"/>\n"; - out<<" </PPointData>\n"; - if (cellDataNames.size() > 0) - { - out<<" <PCellData>\n"; - for(size_t s=0; s<cellDataNames.size(); s++) - out<< " <PDataArray type=\"Float32\" Name=\""<< cellDataNames[s] <<"\"/>\n"; - out<<" </PCellData>\n"; - } - - for(size_t s=0; s<pieceSources.size(); s++) - out<<" <Piece Source=\""<<pieceSources[s]<<"\"/>\n"; - out<<" </PUnstructuredGrid>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeParallelFile to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + ".pvtu"; + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeParallelFile to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + // VTK FILE + out << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" + << "\n"; + out << " <PUnstructuredGrid GhostLevel=\"0\">" + << "\n"; + out << " <PPoints>\n"; + out << " <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n"; + out << " </PPoints>\n"; + out << " <PPointData>\n"; + for (size_t s = 0; s < pointDataNames.size(); s++) + out << " <PDataArray type=\"Float32\" Name=\"" << pointDataNames[s] << "\"/>\n"; + out << " </PPointData>\n"; + if (cellDataNames.size() > 0) { + out << " <PCellData>\n"; + for (size_t s = 0; s < cellDataNames.size(); s++) + out << " <PDataArray type=\"Float32\" Name=\"" << cellDataNames[s] << "\"/>\n"; + out << " </PCellData>\n"; + } + + for (size_t s = 0; s < pieceSources.size(); s++) + out << " <Piece Source=\"" << pieceSources[s] << "\"/>\n"; + out << " </PUnstructuredGrid>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeParallelFile to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeLines(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleInt2 >& lines) +string WbWriterVtkXmlBinary::writeLines(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt2> &lines) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeLines to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)lines.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 2 /*nodes per line */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per line */ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of line */ * nofCells * sizeof(unsigned char); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(lines[c]), sizeof(int) ); - out.write( (char*)&val<2>(lines[c]), sizeof(int) ); - - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 2 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 3; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeLines to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeLines to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)lines.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 2 /*nodes per line */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per line */ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of line */ * nofCells * sizeof(unsigned char); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(lines[c]), sizeof(int)); + out.write((char *)&val<2>(lines[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 2 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 3; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeLines to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -//std::string WbWriterVtkXmlBinary::writeLinesWithNodeData(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) +// std::string WbWriterVtkXmlBinary::writeLinesWithNodeData(const string& filename,vector<UbTupleFloat3 >& nodes, +// vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) //{ // string vtkfilename = filename+getFileExtension(); // UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeLinesWithNodeData to "<<vtkfilename<<" - start"); @@ -270,26 +290,23 @@ string WbWriterVtkXmlBinary::writeLines(const string& filename,vector<UbTupleFlo // // //POINTS SECTION // out<<" <Points>\n"; -// out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; -// out<<" </Points>\n"; -// offset += (bytesPerByteVal + bytesPoints); +// out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset +// <<"\" />\n"; out<<" </Points>\n"; offset += (bytesPerByteVal + bytesPoints); // // //CELLS SECTION // out<<" <Cells>\n"; -// out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; -// offset += (bytesPerByteVal + bytesCellConnectivty); -// out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; -// offset += (bytesPerByteVal + bytesCellOffsets); -// out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; -// offset += (bytesPerByteVal + bytesCellTypes); -// out<<" </Cells>\n"; +// out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" +// />\n"; offset += (bytesPerByteVal + bytesCellConnectivty); out<<" <DataArray type=\"Int32\" +// Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; offset += (bytesPerByteVal + +// bytesCellOffsets); out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< +// offset <<"\" />\n "; offset += (bytesPerByteVal + bytesCellTypes); out<<" </Cells>\n"; // // //DATA SECTION // out<<" <PointData>\n"; // for(size_t s=0; s<datanames.size(); ++s) // { -// out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; -// offset += (bytesPerByteVal + bytesScalarData); +// out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< +// offset <<"\" /> \n"; offset += (bytesPerByteVal + bytesScalarData); // } // out<<" </PointData>\n"; // @@ -357,1262 +374,1309 @@ string WbWriterVtkXmlBinary::writeLines(const string& filename,vector<UbTupleFlo // //} /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeTriangles(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleInt3 >& triangles) +string WbWriterVtkXmlBinary::writeTriangles(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt3> &triangles) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeTriangles to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - - int nofNodes = (int)nodes.size(); - int nofCells = (int)triangles.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 - coord */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 3 /*nodes per triangle */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per triangle */ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of triangle */ * nofCells * sizeof(unsigned char); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(triangles[c]), sizeof(int) ); - out.write( (char*)&val<2>(triangles[c]), sizeof(int) ); - out.write( (char*)&val<3>(triangles[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 3 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 5; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out<<flush; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeTriangles to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTriangles to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)triangles.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 - coord */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 3 /*nodes per triangle */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per triangle */ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of triangle */ * nofCells * sizeof(unsigned char); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(triangles[c]), sizeof(int)); + out.write((char *)&val<2>(triangles[c]), sizeof(int)); + out.write((char *)&val<3>(triangles[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 3 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 5; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out << flush; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTriangles to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeTrianglesWithNodeData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt3 >& cells, vector< string >& datanames, vector< vector< double > >& nodedata) +string WbWriterVtkXmlBinary::writeTrianglesWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt3> &cells, vector<string> &datanames, + vector<vector<double>> &nodedata) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeTrianglesWithNodeData to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 3 /*nodes per tri */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per tri */ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of tri */ * nofCells * sizeof(unsigned char); - int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - //DATA SECTION - out<<" <PointData>\n"; - for(size_t s=0; s<datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarData); - } - out<<" </PointData>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 3 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 5; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - - //DATA SECTION - //scalarData - for(size_t s=0; s<datanames.size(); ++s) - { - out.write((char*)&bytesScalarData,bytesPerByteVal); - for(size_t d=0; d<nodedata[s].size(); ++d) - { - //loake kopie machen, da in nodedata "doubles" sind - float tmp = (float)nodedata[s][d]; - out.write((char*)&tmp,sizeof(float)); - } - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeTrianglesWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTrianglesWithNodeData to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 3 /*nodes per tri */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per tri */ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of tri */ * nofCells * sizeof(unsigned char); + int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + // DATA SECTION + out << " <PointData>\n"; + for (size_t s = 0; s < datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </PointData>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 3 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 5; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + + // DATA SECTION + // scalarData + for (size_t s = 0; s < datanames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < nodedata[s].size(); ++d) { + // loake kopie machen, da in nodedata "doubles" sind + float tmp = (float)nodedata[s][d]; + out.write((char *)&tmp, sizeof(float)); + } + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeTrianglesWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeQuads(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells) +string WbWriterVtkXmlBinary::writeQuads(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuads to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<4>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 4 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 8; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out<<flush; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuads to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuads to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<4>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 4 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 8; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out << flush; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuads to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeQuadsWithNodeData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells, vector< string >& datanames, vector< vector< double > >& nodedata) +string WbWriterVtkXmlBinary::writeQuadsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells, vector<string> &datanames, + vector<vector<double>> &nodedata) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuadsWithNodeData to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); - int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - //DATA SECTION - out<<" <PointData>\n"; - for(size_t s=0; s<datanames.size(); ++s) - { - out<< " <DataArray type=\"Float64\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarData); - } - out<<" </PointData>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<4>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 4 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 8; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - - //DATA SECTION - //scalarData - for(size_t s=0; s<datanames.size(); ++s) - { - out.write((char*)&bytesScalarData,bytesPerByteVal); - for(size_t d=0; d<nodedata[s].size(); ++d) - { - //loake kopie machen, da in nodedata "doubles" sind - float tmp = (float)nodedata[s][d]; - out.write((char*)&tmp,sizeof(float)); - } - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuadsWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeData to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); + int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + // DATA SECTION + out << " <PointData>\n"; + for (size_t s = 0; s < datanames.size(); ++s) { + out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </PointData>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<4>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 4 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 8; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + + // DATA SECTION + // scalarData + for (size_t s = 0; s < datanames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < nodedata[s].size(); ++d) { + // loake kopie machen, da in nodedata "doubles" sind + float tmp = (float)nodedata[s][d]; + out.write((char *)&tmp, sizeof(float)); + } + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeQuadsWithCellData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells, vector< string >& datanames, vector< vector< double > >& celldata) +string WbWriterVtkXmlBinary::writeQuadsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells, vector<string> &datanames, + vector<vector<double>> &celldata) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuadsWithCellData to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); - int bytesScalarData = 1 /*scalar */ * nofCells * sizeof(float); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - //DATA SECTION - out<<" <CellData>\n"; - for(size_t s=0; s<datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarData); - } - out<<" </CellData>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<4>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 4 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 8; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - - //DATA SECTION - //scalarData - for(size_t s=0; s<datanames.size(); ++s) - { - out.write((char*)&bytesScalarData,bytesPerByteVal); - for(size_t d=0; d<celldata[s].size(); ++d) - { - //loake kopie machen, da in celldata "doubles" sind - float tmp = (float)celldata[s][d]; - out.write((char*)&tmp,sizeof(float)); - } - } - - out<<"\n</AppendedData>\n"; - - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuadsWithCellData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithCellData to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); + int bytesScalarData = 1 /*scalar */ * nofCells * sizeof(float); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + // DATA SECTION + out << " <CellData>\n"; + for (size_t s = 0; s < datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </CellData>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<4>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 4 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 8; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + + // DATA SECTION + // scalarData + for (size_t s = 0; s < datanames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < celldata[s].size(); ++d) { + // loake kopie machen, da in celldata "doubles" sind + float tmp = (float)celldata[s][d]; + out.write((char *)&tmp, sizeof(float)); + } + } + + out << "\n</AppendedData>\n"; + + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithCellData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt4 >& cells, - vector< string >& nodedatanames, vector< vector< double > >& nodedata, vector< string >& celldatanames, - vector< vector< double > >& celldata ) +string WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt4> &cells, vector<string> &nodedatanames, + vector<vector<double>> &nodedata, + vector<string> &celldatanames, + vector<vector<double>> &celldata) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); - int bytesScalarDataPoint = 1 /*scalar */ * nofNodes * sizeof(float); - int bytesScalarDataCell = 1 /*scalar */ * nofCells * sizeof(float); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - // Point DATA SECTION - out<<" <PointData>\n"; - for(size_t s=0; s<nodedatanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< nodedatanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarDataPoint); - } - out<<" </PointData>\n"; - - - // Cell DATA SECTION - out<<" <CellData>\n"; - for(size_t s=0; s<celldatanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< celldatanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarDataCell); - } - out<<" </CellData>\n"; - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<4>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 4 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 8; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - - //Point DATA SECTION - //scalarData - for(size_t s=0; s<nodedatanames.size(); ++s) - { - out.write((char*)&bytesScalarDataPoint,bytesPerByteVal); - for(size_t d=0; d<nodedata[s].size(); ++d) - { - //loake kopie machen, da in nodedata "doubles" sind - float tmp = (float)nodedata[s][d]; - out.write((char*)&tmp,sizeof(float)); - } - } - //Cell DATA SECTION - //scalarData - for(size_t s=0; s<celldatanames.size(); ++s) - { - out.write((char*)&bytesScalarDataCell,bytesPerByteVal); - for(size_t d=0; d<celldata[s].size(); ++d) - { - //loake kopie machen, da in celldata "doubles" sind - float tmp = (float)celldata[s][d]; - out.write((char*)&tmp,sizeof(float)); - } - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 4 /*nodes per quad */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per quad */ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of quad */ * nofCells * sizeof(unsigned char); + int bytesScalarDataPoint = 1 /*scalar */ * nofNodes * sizeof(float); + int bytesScalarDataCell = 1 /*scalar */ * nofCells * sizeof(float); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + // Point DATA SECTION + out << " <PointData>\n"; + for (size_t s = 0; s < nodedatanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << nodedatanames[s] + << "\" format=\"appended\" offset=\"" << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarDataPoint); + } + out << " </PointData>\n"; + + // Cell DATA SECTION + out << " <CellData>\n"; + for (size_t s = 0; s < celldatanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << celldatanames[s] + << "\" format=\"appended\" offset=\"" << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarDataCell); + } + out << " </CellData>\n"; + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<4>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 4 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 8; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + + // Point DATA SECTION + // scalarData + for (size_t s = 0; s < nodedatanames.size(); ++s) { + out.write((char *)&bytesScalarDataPoint, bytesPerByteVal); + for (size_t d = 0; d < nodedata[s].size(); ++d) { + // loake kopie machen, da in nodedata "doubles" sind + float tmp = (float)nodedata[s][d]; + out.write((char *)&tmp, sizeof(float)); + } + } + // Cell DATA SECTION + // scalarData + for (size_t s = 0; s < celldatanames.size(); ++s) { + out.write((char *)&bytesScalarDataCell, bytesPerByteVal); + for (size_t d = 0; d < celldata[s].size(); ++d) { + // loake kopie machen, da in celldata "doubles" sind + float tmp = (float)celldata[s][d]; + out.write((char *)&tmp, sizeof(float)); + } + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeQuadsWithNodeAndCellData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeOctsWithCellData(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleInt8 >& cells, vector<string >& datanames, vector<vector<double > >& celldata) +string WbWriterVtkXmlBinary::writeOctsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt8> &cells, vector<string> &datanames, + vector<vector<double>> &celldata) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeOctsWithCellData to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 8 /*nodes per oct */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char); - int bytesScalarData = 1 /*scalar */ * nofCells * sizeof(float); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - //DATA SECTION - out<<" <CellData>\n"; - for(size_t s=0; s<datanames.size(); ++s) - { - out<< " <DataArray type=\"Float32\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarData); - } - out<<" </CellData>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<4>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - out.write( (char*)&val<5>(cells[c]), sizeof(int) ); - out.write( (char*)&val<6>(cells[c]), sizeof(int) ); - out.write( (char*)&val<8>(cells[c]), sizeof(int) ); - out.write( (char*)&val<7>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 8 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 11; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - - //DATA SECTION - //scalarData - for(size_t s=0; s<datanames.size(); ++s) - { - out.write((char*)&bytesScalarData,bytesPerByteVal); - for(size_t d=0; d<celldata[s].size(); ++d) - { - //loake kopie machen, da in celldata "doubles" sind - float tmp = (float)celldata[s][d]; - out.write((char*)&tmp,sizeof(float)); - } - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeOctsWithCellData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithCellData to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 8 /*nodes per oct */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char); + int bytesScalarData = 1 /*scalar */ * nofCells * sizeof(float); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + // DATA SECTION + out << " <CellData>\n"; + for (size_t s = 0; s < datanames.size(); ++s) { + out << " <DataArray type=\"Float32\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </CellData>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<4>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + out.write((char *)&val<5>(cells[c]), sizeof(int)); + out.write((char *)&val<6>(cells[c]), sizeof(int)); + out.write((char *)&val<8>(cells[c]), sizeof(int)); + out.write((char *)&val<7>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 8 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 11; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + + // DATA SECTION + // scalarData + for (size_t s = 0; s < datanames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < celldata[s].size(); ++d) { + // loake kopie machen, da in celldata "doubles" sind + float tmp = (float)celldata[s][d]; + out.write((char *)&tmp, sizeof(float)); + } + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithCellData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeOctsWithNodeData(const string& filename,vector<UbTupleFloat3 >& nodes, vector<UbTupleUInt8 >& cells, vector<string >& datanames, vector<vector<double > >& nodedata) +string WbWriterVtkXmlBinary::writeOctsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleUInt8> &cells, vector<string> &datanames, + vector<vector<double>> &nodedata) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeOctsWithNodeData to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 8 /*nodes per oct */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char); - int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(double); - - unsigned long long offset = 0; - //VTK FILE - out<<"<?xml version=\"2.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - //DATA SECTION - out<<" <PointData>\n"; - for(size_t s=0; s<datanames.size(); ++s) - { - out<< " <DataArray type=\"Float64\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarData); - } - out<<" </PointData>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<4>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - out.write( (char*)&val<5>(cells[c]), sizeof(int) ); - out.write( (char*)&val<6>(cells[c]), sizeof(int) ); - out.write( (char*)&val<8>(cells[c]), sizeof(int) ); - out.write( (char*)&val<7>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 8 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 11; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - - //DATA SECTION - //scalarData - for(size_t s=0; s<datanames.size(); ++s) - { - out.write((char*)&bytesScalarData,bytesPerByteVal); - for(size_t d=0; d<nodedata[s].size(); ++d) - { - //loake kopie machen, da in nodedata "doubles" sind - //float tmp = (float)nodedata[s][d]; - //out.write((char*)&tmp,sizeof(float)); - double tmp = nodedata[s][d]; - out.write((char*)&tmp,sizeof(double)); - } - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeOctsWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithNodeData to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 8 /*nodes per oct */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char); + int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(double); + + unsigned long long offset = 0; + // VTK FILE + out << "<?xml version=\"2.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + // DATA SECTION + out << " <PointData>\n"; + for (size_t s = 0; s < datanames.size(); ++s) { + out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </PointData>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<4>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + out.write((char *)&val<5>(cells[c]), sizeof(int)); + out.write((char *)&val<6>(cells[c]), sizeof(int)); + out.write((char *)&val<8>(cells[c]), sizeof(int)); + out.write((char *)&val<7>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 8 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 11; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + + // DATA SECTION + // scalarData + for (size_t s = 0; s < datanames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < nodedata[s].size(); ++d) { + // loake kopie machen, da in nodedata "doubles" sind + // float tmp = (float)nodedata[s][d]; + // out.write((char*)&tmp,sizeof(float)); + double tmp = nodedata[s][d]; + out.write((char *)&tmp, sizeof(double)); + } + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOctsWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } /*===============================================================================*/ -string WbWriterVtkXmlBinary::writeOcts(const string& filename,vector< UbTupleFloat3 >& nodes, vector< UbTupleInt8 >& cells) +string WbWriterVtkXmlBinary::writeOcts(const string &filename, vector<UbTupleFloat3> &nodes, vector<UbTupleInt8> &cells) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeOcts to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - int nofCells = (int)cells.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 8 /*nodes per oct */ * nofCells * sizeof(int ); - int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int ); - int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char); - //int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofCells<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&val<1>(cells[c]), sizeof(int) ); - out.write( (char*)&val<2>(cells[c]), sizeof(int) ); - out.write( (char*)&val<4>(cells[c]), sizeof(int) ); - out.write( (char*)&val<3>(cells[c]), sizeof(int) ); - out.write( (char*)&val<5>(cells[c]), sizeof(int) ); - out.write( (char*)&val<6>(cells[c]), sizeof(int) ); - out.write( (char*)&val<8>(cells[c]), sizeof(int) ); - out.write( (char*)&val<7>(cells[c]), sizeof(int) ); - } - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - int itmp; - for(int c=1; c<=nofCells; c++) - { - itmp = 8 * c; - out.write( (char*)&itmp, sizeof(int) ); - } - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 11; - for(int c=0; c<nofCells; c++) - { - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeOcts to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOcts to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + int nofCells = (int)cells.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 8 /*nodes per oct */ * nofCells * sizeof(int); + int bytesCellOffsets = 1 /*offset per oct*/ * nofCells * sizeof(int); + int bytesCellTypes = 1 /*type of oct */ * nofCells * sizeof(unsigned char); + // int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(float); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofCells << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofCells; c++) { + out.write((char *)&val<1>(cells[c]), sizeof(int)); + out.write((char *)&val<2>(cells[c]), sizeof(int)); + out.write((char *)&val<4>(cells[c]), sizeof(int)); + out.write((char *)&val<3>(cells[c]), sizeof(int)); + out.write((char *)&val<5>(cells[c]), sizeof(int)); + out.write((char *)&val<6>(cells[c]), sizeof(int)); + out.write((char *)&val<8>(cells[c]), sizeof(int)); + out.write((char *)&val<7>(cells[c]), sizeof(int)); + } + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + int itmp; + for (int c = 1; c <= nofCells; c++) { + itmp = 8 * c; + out.write((char *)&itmp, sizeof(int)); + } + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 11; + for (int c = 0; c < nofCells; c++) { + out.write((char *)&vtkCellType, sizeof(unsigned char)); + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeOcts to " << vtkfilename << " - end"); + + return vtkfilename; } -std::string WbWriterVtkXmlBinary::writeNodes(const std::string& filename,std::vector< UbTupleFloat3 >& nodes) +std::string WbWriterVtkXmlBinary::writeNodes(const std::string &filename, std::vector<UbTupleFloat3> &nodes) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeNodes to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 1 /*nodes per cell */ * nofNodes * sizeof(int ); - int bytesCellOffsets = 1 /*offset per cell */ * nofNodes * sizeof(int ); - int bytesCellTypes = 1 /*type of line */ * nofNodes * sizeof(unsigned char); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofNodes<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofNodes; c++) - out.write( (char*)&c, sizeof(int) ); - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - for(int c=1; c<=nofNodes; c++) - out.write( (char*)&c, sizeof(int) ); - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 1; - for(int c=0; c<nofNodes; c++) - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeNodes to "<<vtkfilename<<" - end"); - - return vtkfilename; + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodes to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 1 /*nodes per cell */ * nofNodes * sizeof(int); + int bytesCellOffsets = 1 /*offset per cell */ * nofNodes * sizeof(int); + int bytesCellTypes = 1 /*type of line */ * nofNodes * sizeof(unsigned char); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofNodes; c++) + out.write((char *)&c, sizeof(int)); + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + for (int c = 1; c <= nofNodes; c++) + out.write((char *)&c, sizeof(int)); + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 1; + for (int c = 0; c < nofNodes; c++) + out.write((char *)&vtkCellType, sizeof(unsigned char)); + + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodes to " << vtkfilename << " - end"); + + return vtkfilename; } -std::string WbWriterVtkXmlBinary::writeNodesWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) +std::string WbWriterVtkXmlBinary::writeNodesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) { - string vtkfilename = filename+getFileExtension(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeNodesWithNodeData to "<<vtkfilename<<" - start"); - - ofstream out(vtkfilename.c_str(),ios::out | ios::binary); - if(!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - string path = UbSystem::getPathFromString(vtkfilename); - if(path.size()>0){ UbSystem::makeDirectory(path); out.open(vtkfilename.c_str(),ios::out | ios::binary);} - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+vtkfilename); - } - - int nofNodes = (int)nodes.size(); - - int bytesPerByteVal = 4; //==sizeof(int) - int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); - int bytesCellConnectivty = 1 /*nodes per cell */ * nofNodes * sizeof(int ); - int bytesCellOffsets = 1 /*offset per cell*/ * nofNodes * sizeof(int ); - int bytesCellTypes = 1 /*type of oct */ * nofNodes * sizeof(unsigned char); - int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(double); - - int offset = 0; - //VTK FILE - out<<"<?xml version=\"1.0\"?>\n"; - out<<"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >"<<"\n"; - out<<" <UnstructuredGrid>"<<"\n"; - out<<" <Piece NumberOfPoints=\""<<nofNodes<<"\" NumberOfCells=\""<<nofNodes<<"\">\n"; - - //POINTS SECTION - out<<" <Points>\n"; - out<<" <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - out<<" </Points>\n"; - offset += (bytesPerByteVal + bytesPoints); - - //CELLS SECTION - out<<" <Cells>\n"; - out<<" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellConnectivty); - out<<" <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\""<< offset <<"\" />\n"; - offset += (bytesPerByteVal + bytesCellOffsets); - out<<" <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\""<< offset <<"\" />\n "; - offset += (bytesPerByteVal + bytesCellTypes); - out<<" </Cells>\n"; - - //DATA SECTION - out<<" <PointData>\n"; - for(size_t s=0; s<datanames.size(); ++s) - { - out<< " <DataArray type=\"Float64\" Name=\""<< datanames[s] <<"\" format=\"appended\" offset=\""<< offset <<"\" /> \n"; - offset += (bytesPerByteVal + bytesScalarData); - } - out<<" </PointData>\n"; - - out<<" </Piece>\n"; - out<<" </UnstructuredGrid>\n"; - - // AppendedData SECTION - out<<" <AppendedData encoding=\"raw\">\n"; - out<<"_"; - - //POINTS SECTION - out.write((char*)&bytesPoints,bytesPerByteVal); - for(int n=0; n<nofNodes; n++) - { - out.write((char*)&val<1>(nodes[n]),sizeof(float)); - out.write((char*)&val<2>(nodes[n]),sizeof(float)); - out.write((char*)&val<3>(nodes[n]),sizeof(float)); - } - - //CELLS SECTION - //cellConnectivity - out.write( (char*)&bytesCellConnectivty, bytesPerByteVal ); - for(int c=0; c<nofNodes; c++) - out.write( (char*)&c, sizeof(int) ); - - //cellOffsets - out.write( (char*)&bytesCellOffsets, bytesPerByteVal ); - for(int c=1; c<=nofNodes; c++) - out.write( (char*)&c, sizeof(int) ); - - //cellTypes - out.write( (char*)&bytesCellTypes, bytesPerByteVal ); - unsigned char vtkCellType = 1; - for(int c=0; c<nofNodes; c++) - out.write( (char*)&vtkCellType, sizeof(unsigned char) ); - - //DATA SECTION - //scalarData - for(size_t s=0; s<datanames.size(); ++s) - { - out.write((char*)&bytesScalarData,bytesPerByteVal); - for(size_t d=0; d<nodedata[s].size(); ++d) - { - //loake kopie machen, da in nodedata "doubles" sind - //float tmp = (float)nodedata[s][d]; - //out.write((char*)&tmp,sizeof(float)); - double tmp = nodedata[s][d]; - out.write((char*)&tmp, sizeof(double)); - } - } - out<<"\n</AppendedData>\n"; - out<<"</VTKFile>"; - out<<endl; - out.close(); - UBLOG(logDEBUG1,"WbWriterVtkXmlBinary::writeNodesWithNodeData to "<<vtkfilename<<" - end"); - - return vtkfilename; - + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodesWithNodeData to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + int nofNodes = (int)nodes.size(); + + int bytesPerByteVal = 4; //==sizeof(int) + int bytesPoints = 3 /*x1/x2/x3 */ * nofNodes * sizeof(float); + int bytesCellConnectivty = 1 /*nodes per cell */ * nofNodes * sizeof(int); + int bytesCellOffsets = 1 /*offset per cell*/ * nofNodes * sizeof(int); + int bytesCellTypes = 1 /*type of oct */ * nofNodes * sizeof(unsigned char); + int bytesScalarData = 1 /*scalar */ * nofNodes * sizeof(double); + + int offset = 0; + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <UnstructuredGrid>" + << "\n"; + out << " <Piece NumberOfPoints=\"" << nofNodes << "\" NumberOfCells=\"" << nofNodes << "\">\n"; + + // POINTS SECTION + out << " <Points>\n"; + out << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + out << " </Points>\n"; + offset += (bytesPerByteVal + bytesPoints); + + // CELLS SECTION + out << " <Cells>\n"; + out << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellConnectivty); + out << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"" << offset + << "\" />\n"; + offset += (bytesPerByteVal + bytesCellOffsets); + out << " <DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" offset=\"" << offset << "\" />\n "; + offset += (bytesPerByteVal + bytesCellTypes); + out << " </Cells>\n"; + + // DATA SECTION + out << " <PointData>\n"; + for (size_t s = 0; s < datanames.size(); ++s) { + out << " <DataArray type=\"Float64\" Name=\"" << datanames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </PointData>\n"; + + out << " </Piece>\n"; + out << " </UnstructuredGrid>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + // POINTS SECTION + out.write((char *)&bytesPoints, bytesPerByteVal); + for (int n = 0; n < nofNodes; n++) { + out.write((char *)&val<1>(nodes[n]), sizeof(float)); + out.write((char *)&val<2>(nodes[n]), sizeof(float)); + out.write((char *)&val<3>(nodes[n]), sizeof(float)); + } + + // CELLS SECTION + // cellConnectivity + out.write((char *)&bytesCellConnectivty, bytesPerByteVal); + for (int c = 0; c < nofNodes; c++) + out.write((char *)&c, sizeof(int)); + + // cellOffsets + out.write((char *)&bytesCellOffsets, bytesPerByteVal); + for (int c = 1; c <= nofNodes; c++) + out.write((char *)&c, sizeof(int)); + + // cellTypes + out.write((char *)&bytesCellTypes, bytesPerByteVal); + unsigned char vtkCellType = 1; + for (int c = 0; c < nofNodes; c++) + out.write((char *)&vtkCellType, sizeof(unsigned char)); + + // DATA SECTION + // scalarData + for (size_t s = 0; s < datanames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < nodedata[s].size(); ++d) { + // loake kopie machen, da in nodedata "doubles" sind + // float tmp = (float)nodedata[s][d]; + // out.write((char*)&tmp,sizeof(float)); + double tmp = nodedata[s][d]; + out.write((char *)&tmp, sizeof(double)); + } + } + out << "\n</AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlBinary::writeNodesWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; } diff --git a/src/basics/basics/writer/WbWriterVtkXmlBinary.h b/src/basics/basics/writer/WbWriterVtkXmlBinary.h index 2beda26b7..393c6bb13 100644 --- a/src/basics/basics/writer/WbWriterVtkXmlBinary.h +++ b/src/basics/basics/writer/WbWriterVtkXmlBinary.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -37,87 +37,113 @@ #include <basics/writer/WbWriter.h> -class WbWriterVtkXmlBinary : public WbWriter +class WbWriterVtkXmlBinary : public WbWriter { public: - static WbWriterVtkXmlBinary* getInstance() - { - static WbWriterVtkXmlBinary instance; - return &instance; - } + static WbWriterVtkXmlBinary *getInstance() + { + static WbWriterVtkXmlBinary instance; + return &instance; + } - WbWriterVtkXmlBinary( const WbWriterVtkXmlBinary& ) = delete; - const WbWriterVtkXmlBinary& operator=( const WbWriterVtkXmlBinary& ) = delete; + WbWriterVtkXmlBinary(const WbWriterVtkXmlBinary &) = delete; + const WbWriterVtkXmlBinary &operator=(const WbWriterVtkXmlBinary &) = delete; private: - WbWriterVtkXmlBinary() : WbWriter() - { - if(sizeof(unsigned char)!=1) throw UbException(UB_EXARGS,"machine error char type mismatch"); - if(sizeof(int) !=4) throw UbException(UB_EXARGS,"machine error int type mismatch"); - if(sizeof(float) !=4) throw UbException(UB_EXARGS,"machine error float type mismatch"); - } - - static const std::string pvdEndTag; + WbWriterVtkXmlBinary() : WbWriter() + { + if (sizeof(unsigned char) != 1) + throw UbException(UB_EXARGS, "machine error char type mismatch"); + if (sizeof(int) != 4) + throw UbException(UB_EXARGS, "machine error int type mismatch"); + if (sizeof(float) != 4) + throw UbException(UB_EXARGS, "machine error float type mismatch"); + } + + static const std::string pvdEndTag; + public: - std::string getFileExtension() override { return ".bin.vtu"; } - - //write a metafile - std::string writeCollection(const std::string& filename, const std::vector<std::string>& filenames, const double& timestep, const bool& sepGroups); - std::string addFilesToCollection(const std::string& filename, const std::vector<std::string>& filenames, const double& timestep, const bool& sepGroups); - std::string writeParallelFile(const std::string& filename,std::vector<std::string>& pieceSources, std::vector<std::string>& pointDataNames, std::vector<std::string>& cellDataNames); - - ////////////////////////////////////////////////////////////////////////// - //nodes - std::string writeNodes(const std::string& filename,std::vector< UbTupleFloat3 >& nodes) override; - std::string writeNodesWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) override; - - ////////////////////////////////////////////////////////////////////////// - //lines - // 0 ---- 1 - //nodenumbering must start with 0! - std::string writeLines(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt2 >& lines) override; - //std::string writeLinesWithNodeData(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata); + std::string getFileExtension() override { return ".bin.vtu"; } + + // write a metafile + std::string writeCollection(const std::string &filename, const std::vector<std::string> &filenames, + const double ×tep, const bool &sepGroups); + std::string addFilesToCollection(const std::string &filename, const std::vector<std::string> &filenames, + const double ×tep, const bool &sepGroups); + std::string writeParallelFile(const std::string &filename, std::vector<std::string> &pieceSources, + std::vector<std::string> &pointDataNames, std::vector<std::string> &cellDataNames); + + ////////////////////////////////////////////////////////////////////////// + // nodes + std::string writeNodes(const std::string &filename, std::vector<UbTupleFloat3> &nodes) override; + std::string writeNodesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + + ////////////////////////////////////////////////////////////////////////// + // lines + // 0 ---- 1 + // nodenumbering must start with 0! + std::string writeLines(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt2> &lines) override; + // std::string writeLinesWithNodeData(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, + // std::vector<UbTupleInt2 >& lines, std::vector< std::string >& datanames, std::vector< std::vector< double > >& + // nodedata); // FIXME: hides function in base class - ////////////////////////////////////////////////////////////////////////// - //triangles - // 2 - // - // 0---1 - //nodenumbering must start with 0! - std::string writeTriangles(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt3 >& triangles) override; - std::string writeTrianglesWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt3 >& cells, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) override; - - ////////////////////////////////////////////////////////////////////////// - //2D - //cell numbering: - // 3---2 - // | | - // 0---1 - //nodenumbering must start with 0! - - std::string writeQuads(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells) override; - std::string writeQuadsWithNodeData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& nodedata) override; - std::string writeQuadsWithCellData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells, std::vector< std::string >& datanames, std::vector< std::vector< double > >& celldata) override; - std::string writeQuadsWithNodeAndCellData(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt4 >& cells, - std::vector< std::string >& nodedatanames, std::vector< std::vector< double > >& nodedata, std::vector< std::string >& celldatanames, - std::vector< std::vector< double > >& celldata ) override; - - ////////////////////////////////////////////////////////////////////////// - //octs - // 7 ---- 6 - // /| /| - // 4 +--- 5 | - // | | | | - // | 3 ---+ 2 - // |/ |/ - // 0 ---- 1 - std::string writeOcts(const std::string& filename,std::vector< UbTupleFloat3 >& nodes, std::vector< UbTupleInt8 >& cells) override; - std::string writeOctsWithCellData(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt8 >& cells, std::vector<std::string >& datanames, std::vector<std::vector<double > >& celldata) override; - std::string writeOctsWithNodeData(const std::string& filename,std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleUInt8 >& cells, std::vector<std::string >& datanames, std::vector<std::vector<double > >& nodedata) override; - -private: + ////////////////////////////////////////////////////////////////////////// + // triangles + // 2 + // + // 0---1 + // nodenumbering must start with 0! + std::string writeTriangles(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt3> &triangles) override; + std::string writeTrianglesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt3> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + + ////////////////////////////////////////////////////////////////////////// + // 2D + // cell numbering: + // 3---2 + // | | + // 0---1 + // nodenumbering must start with 0! + std::string writeQuads(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells) override; + std::string writeQuadsWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + std::string writeQuadsWithCellData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &celldata) override; + std::string writeQuadsWithNodeAndCellData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt4> &cells, std::vector<std::string> &nodedatanames, + std::vector<std::vector<double>> &nodedata, + std::vector<std::string> &celldatanames, + std::vector<std::vector<double>> &celldata) override; + + ////////////////////////////////////////////////////////////////////////// + // octs + // 7 ---- 6 + // /| /| + // 4 +--- 5 | + // | | | | + // | 3 ---+ 2 + // |/ |/ + // 0 ---- 1 + std::string writeOcts(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt8> &cells) override; + std::string writeOctsWithCellData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt8> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &celldata) override; + std::string writeOctsWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleUInt8> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + +private: }; -#endif //WBWRITERVTKXMLBINARY_H +#endif // WBWRITERVTKXMLBINARY_H diff --git a/src/basics/geometry3d/CoordinateTransformation3D.cpp b/src/basics/geometry3d/CoordinateTransformation3D.cpp index c54d0e1c6..be758ced5 100644 --- a/src/basics/geometry3d/CoordinateTransformation3D.cpp +++ b/src/basics/geometry3d/CoordinateTransformation3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,29 +30,36 @@ //! \ingroup geometry3d //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#include <geometry3d/CoordinateTransformation3D.h> #include <basics/utilities/UbMath.h> +#include <geometry3d/CoordinateTransformation3D.h> using namespace std; CoordinateTransformation3D::CoordinateTransformation3D() { - this->setTransformationValues(0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0); + this->setTransformationValues(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0); } /*======================================================*/ -CoordinateTransformation3D::CoordinateTransformation3D(const double& originX1, const double& originX2, const double& originX3, const double& dx1, const double& dx2, const double& dx3, const double& alpha, const double& beta, const double& gamma) +CoordinateTransformation3D::CoordinateTransformation3D(const double &originX1, const double &originX2, + const double &originX3, const double &dx1, const double &dx2, + const double &dx3, const double &alpha, const double &beta, + const double &gamma) { - this->setTransformationValues(originX1, originX2, originX3, dx1, dx2, dx3, alpha, beta, gamma); + this->setTransformationValues(originX1, originX2, originX3, dx1, dx2, dx3, alpha, beta, gamma); } /*======================================================*/ -CoordinateTransformation3D::CoordinateTransformation3D(const double& originX1, const double& originX2, const double& originX3, const double& dx1, const double& dx2, const double& dx3) +CoordinateTransformation3D::CoordinateTransformation3D(const double &originX1, const double &originX2, + const double &originX3, const double &dx1, const double &dx2, + const double &dx3) { - this->setTransformationValues(originX1, originX2, originX3, dx1, dx2, dx3, 0.0, 0.0, 0.0); + this->setTransformationValues(originX1, originX2, originX3, dx1, dx2, dx3, 0.0, 0.0, 0.0); } /*======================================================*/ -CoordinateTransformation3D::CoordinateTransformation3D(CoordinateTransformation3D* transformation) +CoordinateTransformation3D::CoordinateTransformation3D(CoordinateTransformation3D *transformation) { - this->setTransformationValues(transformation->Tx1 , transformation->Tx2 , transformation->Tx3 , transformation->Sx1 , transformation->Sx2 , transformation->Sx3, transformation->alpha, transformation->beta, transformation->gamma); + this->setTransformationValues(transformation->Tx1, transformation->Tx2, transformation->Tx3, transformation->Sx1, + transformation->Sx2, transformation->Sx3, transformation->alpha, transformation->beta, + transformation->gamma); } /*======================================================*/ // void CoordinateTransformation3D::init() @@ -60,7 +67,7 @@ CoordinateTransformation3D::CoordinateTransformation3D(CoordinateTransformation3 // this->Tx1 = 0.0; this->Tx2 = 0.0; this->Tx3 = 0.0; // this->Sx1 = 1.0; this->Sx2 = 1.0; this->Sx3 = 1.0; // this->alpha = 0.0; this->beta = 0.0; this->gamma = 0.0; -// +// // this->toX1factorX1 = 1.0; this->toX1factorX2 = 0.0; this->toX1factorX3 = 0.0; // this->toX2factorX1 = 0.0; this->toX2factorX2 = 1.0; this->toX2factorX3 = 0.0; // this->toX3factorX1 = 0.0; this->toX3factorX2 = 0.0; this->toX3factorX3 = 1.0; @@ -68,7 +75,7 @@ CoordinateTransformation3D::CoordinateTransformation3D(CoordinateTransformation3 // this->fromX1factorX1 = 1.0; this->fromX1factorX2 = 0.0; this->fromX1factorX3 = 0.0; // this->fromX2factorX1 = 0.0; this->fromX2factorX2 = 1.0; this->fromX2factorX3 = 0.0; // this->fromX3factorX1 = 0.0; this->fromX3factorX2 = 0.0; this->fromX3factorX3 = 1.0; -// +// // this->active = false; // this->transformation = false; // } @@ -84,88 +91,95 @@ CoordinateTransformation3D::CoordinateTransformation3D(CoordinateTransformation3 @param dx2 y coordinate scaling (dy_transformed/dy_global) @param dx3 z coordinate scaling (dz_transformed/dz_global) @param alpha rotation around z angle (positive FROM global TO transformed coordinate system) -@param beta rotation around y angle -@param gamma rotation around x angle +@param beta rotation around y angle +@param gamma rotation around x angle @exception IllegalArgumentException if c1 of the scale values is between -1.0E-8 and 1.0E-8 */ -void CoordinateTransformation3D::setTransformationValues(const double& originX1, const double& originX2, const double& originX3, const double& dx1, const double& dx2, const double& dx3, const double& alpha, const double& beta, const double& gamma) +void CoordinateTransformation3D::setTransformationValues(const double &originX1, const double &originX2, + const double &originX3, const double &dx1, const double &dx2, + const double &dx3, const double &alpha, const double &beta, + const double &gamma) { - if(UbMath::zero(dx1) || UbMath::zero(dx2) || UbMath::zero(dx3)) - throw UbException(UB_EXARGS,"error: at least one delta==0.0"); - - this->Tx1 = originX1; this->Tx2 = originX2; this->Tx3 = originX3; - this->Sx1 = dx1; this->Sx2 = dx2; this->Sx3 = dx3; - this->alpha = alpha; this->beta = beta; this->gamma = gamma; + if (UbMath::zero(dx1) || UbMath::zero(dx2) || UbMath::zero(dx3)) + throw UbException(UB_EXARGS, "error: at least one delta==0.0"); + + this->Tx1 = originX1; + this->Tx2 = originX2; + this->Tx3 = originX3; + this->Sx1 = dx1; + this->Sx2 = dx2; + this->Sx3 = dx3; + this->alpha = alpha; + this->beta = beta; + this->gamma = gamma; + + double ra = UbMath::PI * alpha / 180.0; + double cosA = cos(ra); + double sinA = sin(ra); + double rb = UbMath::PI * beta / 180.0; + double cosB = cos(rb); + double sinB = sin(rb); + double rg = UbMath::PI * gamma / 180.0; + double cosG = cos(rg); + double sinG = sin(rg); + + // Matrix-Werte von T_invers (indizes: 12 = spalte 1 zeile 2) + double divisor = (Sx1 * Sx2 * Sx3); + + this->toX1factorX1 = +cosB * cosA * Sx2 * Sx3 / divisor; + this->toX1factorX2 = -cosB * sinA * Sx1 * Sx3 / divisor; + this->toX1factorX3 = +sinB * Sx1 * Sx2 / divisor; + this->toX1delta = + (-Tx3 * Sx1 * Sx2 * sinB + Tx2 * Sx1 * Sx3 * sinA * cosB - Tx1 * Sx2 * Sx3 * cosB * cosA) / divisor; + + this->toX2factorX1 = Sx2 * Sx3 * (sinG * sinB * cosA + cosG * sinA) / divisor; + this->toX2factorX2 = Sx1 * Sx3 * (-sinG * sinB * sinA + cosG * cosA) / divisor; + this->toX2factorX3 = -Sx1 * Sx2 * cosB * sinG / divisor; + this->toX2delta = + (-Tx2 * Sx1 * Sx3 * cosG * cosA + Tx3 * Sx1 * Sx2 * sinG * cosB + Tx2 * Sx1 * Sx3 * sinG * sinA * sinB - + Tx1 * Sx2 * Sx3 * cosG * sinA - Tx1 * Sx2 * Sx3 * sinB * sinG * cosA) / + divisor; + + this->toX3factorX1 = Sx2 * Sx3 * (-cosG * sinB * cosA + sinG * sinA) / divisor; + this->toX3factorX2 = Sx1 * Sx3 * (sinB * cosG * sinA + sinG * cosA) / divisor; + this->toX3factorX3 = Sx1 * Sx2 * cosB * cosG / divisor; + this->toX3delta = + (-Tx2 * Sx1 * Sx3 * sinG * cosA - Tx3 * Sx1 * Sx2 * cosG * cosB - Tx2 * Sx1 * Sx3 * cosG * sinA * sinB - + Tx1 * Sx2 * Sx3 * sinG * sinA + Tx1 * Sx2 * Sx3 * sinB * cosG * cosA) / + divisor; - double ra = UbMath::PI*alpha/180.0; - double cosA = cos(ra); - double sinA = sin(ra); - double rb = UbMath::PI*beta/180.0; - double cosB = cos(rb); - double sinB = sin(rb); - double rg = UbMath::PI*gamma/180.0; - double cosG = cos(rg); - double sinG = sin(rg); + // Matrix-Werte von T_invers (indizes: 12 = spalte 1 zeile 2) + this->fromX1factorX1 = cosB * cosA * Sx1; + this->fromX1factorX2 = (sinG * sinB * cosA + cosG * sinA) * Sx1; + this->fromX1factorX3 = (-cosG * sinB * cosA + sinG * sinA) * Sx1; + this->fromX1delta = Tx1; - //Matrix-Werte von T_invers (indizes: 12 = spalte 1 zeile 2) - double divisor = (Sx1*Sx2*Sx3); - - this->toX1factorX1 = +cosB*cosA*Sx2*Sx3/divisor; - this->toX1factorX2 = -cosB*sinA*Sx1*Sx3/divisor; - this->toX1factorX3 = +sinB*Sx1*Sx2/divisor; - this->toX1delta = (-Tx3*Sx1*Sx2*sinB - +Tx2*Sx1*Sx3*sinA*cosB - -Tx1*Sx2*Sx3*cosB*cosA)/divisor; - - this->toX2factorX1 = Sx2*Sx3*(sinG*sinB*cosA+cosG*sinA)/divisor; - this->toX2factorX2 = Sx1*Sx3*(-sinG*sinB*sinA+cosG*cosA)/divisor; - this->toX2factorX3 = -Sx1*Sx2*cosB*sinG/divisor; - this->toX2delta = (-Tx2*Sx1*Sx3*cosG*cosA - +Tx3*Sx1*Sx2*sinG*cosB - +Tx2*Sx1*Sx3*sinG*sinA*sinB - -Tx1*Sx2*Sx3*cosG*sinA - -Tx1*Sx2*Sx3*sinB*sinG*cosA )/divisor; - + this->fromX2factorX1 = -cosB * sinA * Sx2; + this->fromX2factorX2 = -(sinG * sinB * sinA - cosG * cosA) * Sx2; + this->fromX2factorX3 = (cosG * sinB * sinA + sinG * cosA) * Sx2; + this->fromX2delta = Tx2; - this->toX3factorX1 = Sx2*Sx3*(-cosG*sinB*cosA+sinG*sinA)/divisor; - this->toX3factorX2 = Sx1*Sx3*(sinB*cosG*sinA+sinG*cosA)/divisor; - this->toX3factorX3 = Sx1*Sx2*cosB*cosG/divisor; - this->toX3delta = (-Tx2*Sx1*Sx3*sinG*cosA - -Tx3*Sx1*Sx2*cosG*cosB - -Tx2*Sx1*Sx3*cosG*sinA*sinB - -Tx1*Sx2*Sx3*sinG*sinA - +Tx1*Sx2*Sx3*sinB*cosG*cosA )/divisor; - - //Matrix-Werte von T_invers (indizes: 12 = spalte 1 zeile 2) - this->fromX1factorX1 = cosB*cosA*Sx1; - this->fromX1factorX2 = (sinG*sinB*cosA+cosG*sinA)*Sx1; - this->fromX1factorX3 = (-cosG*sinB*cosA+sinG*sinA)*Sx1; - this->fromX1delta = Tx1; + this->fromX3factorX1 = sinB * Sx3; + this->fromX3factorX2 = -sinG * cosB * Sx3; + this->fromX3factorX3 = cosG * cosB * Sx3; + this->fromX3delta = Tx3; - this->fromX2factorX1 = -cosB*sinA*Sx2; - this->fromX2factorX2 = -(sinG*sinB*sinA-cosG*cosA)*Sx2; - this->fromX2factorX3 = (cosG*sinB*sinA+sinG*cosA)*Sx2; - this->fromX2delta = Tx2; - - this->fromX3factorX1 = sinB*Sx3; - this->fromX3factorX2 = -sinG*cosB*Sx3; - this->fromX3factorX3 = cosG*cosB*Sx3; - this->fromX3delta = Tx3; + this->active = true; - this->active = true; - - this->transformation = true; + this->transformation = true; } /*======================================================*/ /*! Set transformation active state (if this IS a transformation) @param active true to be active, false otherwise **/ -void CoordinateTransformation3D::setActive(const bool& active) +void CoordinateTransformation3D::setActive(const bool &active) { - if(this->active == active) return; - if(this->transformation) this->active = active; + if (this->active == active) + return; + if (this->transformation) + this->active = active; } /*======================================================*/ /*! @@ -174,44 +188,59 @@ Transform FROM global coordinates TO transformed coordinates. @param x2 the global y coordinate @param x3 the global z coordinate **/ -double CoordinateTransformation3D::transformForwardToX1Coordinate(const double& x1, const double& x2, const double& x3) const +double CoordinateTransformation3D::transformForwardToX1Coordinate(const double &x1, const double &x2, + const double &x3) const { - if(this->active) return this->toX1factorX1*x1 + this->toX1factorX2*x2 + this->toX1factorX3*x3 + this->toX1delta; - else return x1; + if (this->active) + return this->toX1factorX1 * x1 + this->toX1factorX2 * x2 + this->toX1factorX3 * x3 + this->toX1delta; + else + return x1; } /*======================================================*/ -double CoordinateTransformation3D::transformForwardToX2Coordinate(const double& x1, const double& x2, const double& x3) const +double CoordinateTransformation3D::transformForwardToX2Coordinate(const double &x1, const double &x2, + const double &x3) const { - if(this->active) return this->toX2factorX1*x1 + this->toX2factorX2*x2 + this->toX2factorX3*x3 + this->toX2delta; - else return x2; + if (this->active) + return this->toX2factorX1 * x1 + this->toX2factorX2 * x2 + this->toX2factorX3 * x3 + this->toX2delta; + else + return x2; } /*======================================================*/ -double CoordinateTransformation3D::transformForwardToX3Coordinate(const double& x1, const double& x2, const double& x3) const +double CoordinateTransformation3D::transformForwardToX3Coordinate(const double &x1, const double &x2, + const double &x3) const { - if(this->active) return this->toX3factorX1*x1 + this->toX3factorX2*x2 + this->toX3factorX3*x3 + this->toX3delta; - else return x3; + if (this->active) + return this->toX3factorX1 * x1 + this->toX3factorX2 * x2 + this->toX3factorX3 * x3 + this->toX3delta; + else + return x3; } /*======================================================*/ /*! Transform FROM global coordinates TO transformed coordinates (ignoring rotation). @param x1 the global x coordinate **/ -double CoordinateTransformation3D::transformForwardToX1CoordinateIgnoringRotation(const double& x1) const +double CoordinateTransformation3D::transformForwardToX1CoordinateIgnoringRotation(const double &x1) const { - if(this->active) return (x1-this->Tx1)/this->Sx1; - else return x1; + if (this->active) + return (x1 - this->Tx1) / this->Sx1; + else + return x1; } /*======================================================*/ -double CoordinateTransformation3D::transformForwardToX2CoordinateIgnoringRotation(const double& x2) const +double CoordinateTransformation3D::transformForwardToX2CoordinateIgnoringRotation(const double &x2) const { - if(this->active) return (x2-this->Tx2)/this->Sx2; - else return x2; + if (this->active) + return (x2 - this->Tx2) / this->Sx2; + else + return x2; } /*======================================================*/ -double CoordinateTransformation3D::transformForwardToX3CoordinateIgnoringRotation(const double& x3) const +double CoordinateTransformation3D::transformForwardToX3CoordinateIgnoringRotation(const double &x3) const { - if(this->active) return (x3-this->Tx3)/this->Sx3; - else return x3; + if (this->active) + return (x3 - this->Tx3) / this->Sx3; + else + return x3; } /*======================================================*/ /*! @@ -220,44 +249,59 @@ Transform FROM transformed coordinates TO global coordinates. @param x2 the transformed y coordinate @param x3 the transformed z coordinate **/ -double CoordinateTransformation3D::transformBackwardToX1Coordinate(const double& x1, const double& x2, const double& x3) const +double CoordinateTransformation3D::transformBackwardToX1Coordinate(const double &x1, const double &x2, + const double &x3) const { - if(this->active) return this->fromX1factorX1*x1 + this->fromX1factorX2*x2 + this->fromX1factorX3*x3 + this->fromX1delta; - else return x1; + if (this->active) + return this->fromX1factorX1 * x1 + this->fromX1factorX2 * x2 + this->fromX1factorX3 * x3 + this->fromX1delta; + else + return x1; } /*======================================================*/ -double CoordinateTransformation3D::transformBackwardToX2Coordinate(const double& x1, const double& x2, const double& x3) const +double CoordinateTransformation3D::transformBackwardToX2Coordinate(const double &x1, const double &x2, + const double &x3) const { - if(this->active) return this->fromX2factorX1*x1 + this->fromX2factorX2*x2 + this->fromX2factorX3*x3 + this->fromX2delta; - else return x2; + if (this->active) + return this->fromX2factorX1 * x1 + this->fromX2factorX2 * x2 + this->fromX2factorX3 * x3 + this->fromX2delta; + else + return x2; } /*======================================================*/ -double CoordinateTransformation3D::transformBackwardToX3Coordinate(const double& x1, const double& x2, const double& x3) const +double CoordinateTransformation3D::transformBackwardToX3Coordinate(const double &x1, const double &x2, + const double &x3) const { - if(this->active) return this->fromX3factorX1*x1 + this->fromX3factorX2*x2 + this->fromX3factorX3*x3 + this->fromX3delta; - else return x3; + if (this->active) + return this->fromX3factorX1 * x1 + this->fromX3factorX2 * x2 + this->fromX3factorX3 * x3 + this->fromX3delta; + else + return x3; } /*======================================================*/ /*! Transform FROM transformed coordinates TO global coordinates (ignoring rotation). @param x1 the transformed x coordinate **/ -double CoordinateTransformation3D::transformBackwardToX1CoordinateIgnoringRotation(const double& x1) const +double CoordinateTransformation3D::transformBackwardToX1CoordinateIgnoringRotation(const double &x1) const { - if(this->active) return x1*this->Sx1+this->Tx1; - else return x1; + if (this->active) + return x1 * this->Sx1 + this->Tx1; + else + return x1; } /*======================================================*/ -double CoordinateTransformation3D::transformBackwardToX2CoordinateIgnoringRotation(const double& x2) const +double CoordinateTransformation3D::transformBackwardToX2CoordinateIgnoringRotation(const double &x2) const { - if(this->active) return x2*this->Sx2+this->Tx2; - else return x2; + if (this->active) + return x2 * this->Sx2 + this->Tx2; + else + return x2; } /*======================================================*/ -double CoordinateTransformation3D::transformBackwardToX3CoordinateIgnoringRotation(const double& x3) const +double CoordinateTransformation3D::transformBackwardToX3CoordinateIgnoringRotation(const double &x3) const { - if(this->active) return x3*this->Sx3+this->Tx3; - else return x3; + if (this->active) + return x3 * this->Sx3 + this->Tx3; + else + return x3; } /*======================================================*/ /*! @@ -266,23 +310,22 @@ Returns a string representation of this transformation. **/ string CoordinateTransformation3D::toString() const { - stringstream ss; - ss<<" CoordinateTransformation3D\n"; -// ss<<"[isTransformation="<<this->transformation; -// ss<<", isActive="<<this->active<<endl; - ss<<" ,a="<<this->Tx1<<", b="<<this->Tx2<<", c="<<this->Tx3<<endl; - ss<<" , dx1="<<this->Sx1<<", dx2="<<this->Sx2<<", dx2="<<this->Sx3<<endl; -// ss<<" , alpha="<<this->alpha<<", beta="<<this->beta<endl; -// ss<<"]"; -// ss<<"[to11="<<this->to11<<", to12="<<this->to12<<", to13="<<this->to13; -// ss<<", to21="<<this->to21<<", to22="<<this->to22<<", to23="<<this->to23; -// ss<<", to31="<<this->to31<<", to32="<<this->to32<<", to33="<<this->to33; -// ss<<", toA="<<this->toA<<", toB="<<this->toB<<", toC="<<this->toC; -// ss<<", from11="<<this->from11<<", from12="<<this->from12<<", from13="<<this->from13; -// ss<<", from21="<<this->from21<<", from22="<<this->from22<<", from23="<<this->from23; -// ss<<", from31="<<this->from31<<", from32="<<this->from32<<", from33="<<this->from33; -// ss<<", fromA="<<this->fromA; ss<<", fromB="<<this->fromB; ss<<", fromC="<<this->fromC; -// ss<<"]}"; - return ss.str(); + stringstream ss; + ss << " CoordinateTransformation3D\n"; + // ss<<"[isTransformation="<<this->transformation; + // ss<<", isActive="<<this->active<<endl; + ss << " ,a=" << this->Tx1 << ", b=" << this->Tx2 << ", c=" << this->Tx3 << endl; + ss << " , dx1=" << this->Sx1 << ", dx2=" << this->Sx2 << ", dx2=" << this->Sx3 << endl; + // ss<<" , alpha="<<this->alpha<<", beta="<<this->beta<endl; + // ss<<"]"; + // ss<<"[to11="<<this->to11<<", to12="<<this->to12<<", to13="<<this->to13; + // ss<<", to21="<<this->to21<<", to22="<<this->to22<<", to23="<<this->to23; + // ss<<", to31="<<this->to31<<", to32="<<this->to32<<", to33="<<this->to33; + // ss<<", toA="<<this->toA<<", toB="<<this->toB<<", toC="<<this->toC; + // ss<<", from11="<<this->from11<<", from12="<<this->from12<<", from13="<<this->from13; + // ss<<", from21="<<this->from21<<", from22="<<this->from22<<", from23="<<this->from23; + // ss<<", from31="<<this->from31<<", from32="<<this->from32<<", from33="<<this->from33; + // ss<<", fromA="<<this->fromA; ss<<", fromB="<<this->fromB; ss<<", fromC="<<this->fromC; + // ss<<"]}"; + return ss.str(); } - diff --git a/src/basics/geometry3d/CoordinateTransformation3D.h b/src/basics/geometry3d/CoordinateTransformation3D.h index 112f78789..a0f88c1f6 100644 --- a/src/basics/geometry3d/CoordinateTransformation3D.h +++ b/src/basics/geometry3d/CoordinateTransformation3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,19 +34,19 @@ #define COORDINATETRANSFORMATION3D_H #include <cmath> -#include <string> #include <sstream> +#include <string> #include <basics/utilities/UbException.h> #include <PointerDefinitions.h> /////////////////////////////////////////////////////////////////////////////////////// -//! +//! //! \brief A class provides 3d coordinate transformation //! \details //! description: x1/x2/x3 = old, x1*/x2*/x3* = new -//! x2 +//! x2 //! ^ x* //! | / //! | 2* @@ -59,74 +59,89 @@ //! 1 \ THEN rotation by gamma around "x3" axis //! | x1* //! |--1--2--3--4--5------------- > x1 -//! +//! //! Remark: It might be that the rotations around x1 and x3 axis are swapped. -//! +//! ////////////////////////////////////////////////////////////////////////////////////// class CoordinateTransformation3D { public: - CoordinateTransformation3D(); - CoordinateTransformation3D(const double& originX1, const double& originX2, const double& originX3, const double& dx1, const double& dx2, const double& dx3, const double& alpha, const double& beta, const double& gamma); - CoordinateTransformation3D(const double& originX1, const double& originX2, const double& originX3, const double& dx1, const double& dx2, const double& dx3); - CoordinateTransformation3D(CoordinateTransformation3D* transformation); - - void setTransformationValues(const double& originX1, const double& originX2, const double& originX3, const double& dx1, const double& dx2, const double& dx3, const double& alpha, const double& beta, const double& gamma); - double getX1CoordinateOffset() const { return this->Tx1; } //Translation - double getX2CoordinateOffset() const { return this->Tx2; } - double getX3CoordinateOffset() const { return this->Tx3; } - double getX1CoordinateScaling() const { return this->Sx1; } //Scaling - double getX2CoordinateScaling() const { return this->Sx2; } - double getX3CoordinateScaling() const { return this->Sx3; } - double getRotationX1Angle() const { return this->alpha; } - double getRotationX2Angle() const { return this->beta; } - double getRotationX3Angle() const { return this->gamma; } //Rotation - - //Achtung die Winkel passen nicht ueberein -siehe setTransformationValues - void setRotationX1Angle(double alpha) { this->setTransformationValues(this->Tx1, this->Tx2, this->Tx3, this->Sx1, this->Sx2, this->Sx3, alpha, this->beta, this->gamma); } - void setRotationX2Angle(double beta ) { this->setTransformationValues(this->Tx1, this->Tx2, this->Tx3, this->Sx1, this->Sx2, this->Sx3, this->alpha, beta, this->gamma); } - void setRotationX3Angle(double gamma) { this->setTransformationValues(this->Tx1, this->Tx2, this->Tx3, this->Sx1, this->Sx2, this->Sx3, this->alpha, this->beta, gamma); } - - void setActive(const bool& active); - bool isActive() const { return this->active; } - bool isTransformation() const { return this->transformation; } - - double transformForwardToX1Coordinate(const double& x1, const double& x2, const double& x3) const; - double transformForwardToX2Coordinate(const double& x1, const double& x2, const double& x3) const; - double transformForwardToX3Coordinate(const double& x1, const double& x2, const double& x3) const; - double transformForwardToX1CoordinateIgnoringRotation(const double& x1) const; - double transformForwardToX2CoordinateIgnoringRotation(const double& x2) const; - double transformForwardToX3CoordinateIgnoringRotation(const double& x3) const; - double transformBackwardToX1Coordinate(const double& x1, const double& x2, const double& x3) const; - double transformBackwardToX2Coordinate(const double& x1, const double& x2, const double& x3) const; - double transformBackwardToX3Coordinate(const double& x1, const double& x2, const double& x3) const; - double transformBackwardToX1CoordinateIgnoringRotation(const double& x1) const; - double transformBackwardToX2CoordinateIgnoringRotation(const double& x2) const; - double transformBackwardToX3CoordinateIgnoringRotation(const double& x3) const; - std::string toString() const; + CoordinateTransformation3D(); + CoordinateTransformation3D(const double &originX1, const double &originX2, const double &originX3, + const double &dx1, const double &dx2, const double &dx3, const double &alpha, + const double &beta, const double &gamma); + CoordinateTransformation3D(const double &originX1, const double &originX2, const double &originX3, + const double &dx1, const double &dx2, const double &dx3); + CoordinateTransformation3D(CoordinateTransformation3D *transformation); + + void setTransformationValues(const double &originX1, const double &originX2, const double &originX3, + const double &dx1, const double &dx2, const double &dx3, const double &alpha, + const double &beta, const double &gamma); + double getX1CoordinateOffset() const { return this->Tx1; } // Translation + double getX2CoordinateOffset() const { return this->Tx2; } + double getX3CoordinateOffset() const { return this->Tx3; } + double getX1CoordinateScaling() const { return this->Sx1; } // Scaling + double getX2CoordinateScaling() const { return this->Sx2; } + double getX3CoordinateScaling() const { return this->Sx3; } + double getRotationX1Angle() const { return this->alpha; } + double getRotationX2Angle() const { return this->beta; } + double getRotationX3Angle() const { return this->gamma; } // Rotation + + // Achtung die Winkel passen nicht ueberein -siehe setTransformationValues + void setRotationX1Angle(double alpha) + { + this->setTransformationValues(this->Tx1, this->Tx2, this->Tx3, this->Sx1, this->Sx2, this->Sx3, alpha, + this->beta, this->gamma); + } + void setRotationX2Angle(double beta) + { + this->setTransformationValues(this->Tx1, this->Tx2, this->Tx3, this->Sx1, this->Sx2, this->Sx3, this->alpha, + beta, this->gamma); + } + void setRotationX3Angle(double gamma) + { + this->setTransformationValues(this->Tx1, this->Tx2, this->Tx3, this->Sx1, this->Sx2, this->Sx3, this->alpha, + this->beta, gamma); + } + + void setActive(const bool &active); + bool isActive() const { return this->active; } + bool isTransformation() const { return this->transformation; } + + double transformForwardToX1Coordinate(const double &x1, const double &x2, const double &x3) const; + double transformForwardToX2Coordinate(const double &x1, const double &x2, const double &x3) const; + double transformForwardToX3Coordinate(const double &x1, const double &x2, const double &x3) const; + double transformForwardToX1CoordinateIgnoringRotation(const double &x1) const; + double transformForwardToX2CoordinateIgnoringRotation(const double &x2) const; + double transformForwardToX3CoordinateIgnoringRotation(const double &x3) const; + double transformBackwardToX1Coordinate(const double &x1, const double &x2, const double &x3) const; + double transformBackwardToX2Coordinate(const double &x1, const double &x2, const double &x3) const; + double transformBackwardToX3Coordinate(const double &x1, const double &x2, const double &x3) const; + double transformBackwardToX1CoordinateIgnoringRotation(const double &x1) const; + double transformBackwardToX2CoordinateIgnoringRotation(const double &x2) const; + double transformBackwardToX3CoordinateIgnoringRotation(const double &x3) const; + std::string toString() const; private: - double Tx1, Tx2, Tx3, Sx1, Sx2, Sx3, alpha, beta, gamma; - - double toX1factorX1, toX1factorX2, toX1factorX3, toX1delta; - double toX2factorX1, toX2factorX2, toX2factorX3, toX2delta; - double toX3factorX1, toX3factorX2, toX3factorX3, toX3delta; - - double fromX1factorX1, fromX1factorX2, fromX1factorX3, fromX1delta; - double fromX2factorX1, fromX2factorX2, fromX2factorX3, fromX2delta; - double fromX3factorX1, fromX3factorX2, fromX3factorX3, fromX3delta; + double Tx1, Tx2, Tx3, Sx1, Sx2, Sx3, alpha, beta, gamma; - bool active; - bool transformation; + double toX1factorX1, toX1factorX2, toX1factorX3, toX1delta; + double toX2factorX1, toX2factorX2, toX2factorX3, toX2delta; + double toX3factorX1, toX3factorX2, toX3factorX3, toX3delta; - friend class MPIIOCoProcessor; - friend class MPIIORestartCoProcessor; - friend class MPIIOMigrationCoProcessor; - friend class MPIIOMigrationBECoProcessor; - friend class CheckpointConverter; + double fromX1factorX1, fromX1factorX2, fromX1factorX3, fromX1delta; + double fromX2factorX1, fromX2factorX2, fromX2factorX3, fromX2delta; + double fromX3factorX1, fromX3factorX2, fromX3factorX3, fromX3delta; + bool active; + bool transformation; + friend class MPIIOCoProcessor; + friend class MPIIORestartCoProcessor; + friend class MPIIOMigrationCoProcessor; + friend class MPIIOMigrationBECoProcessor; + friend class CheckpointConverter; }; -#endif //COORDINATETRANSFORMATION3D_H +#endif // COORDINATETRANSFORMATION3D_H diff --git a/src/basics/geometry3d/GbCuboid3D.cpp b/src/basics/geometry3d/GbCuboid3D.cpp index 55bb6331b..3b29cf795 100644 --- a/src/basics/geometry3d/GbCuboid3D.cpp +++ b/src/basics/geometry3d/GbCuboid3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -42,526 +42,514 @@ using namespace std; // Konstruktor GbCuboid3D::GbCuboid3D() : GbObject3D() { - this->setName("cuboid"); - this->p1 = new GbPoint3D(0.0, 0.0, 0.0); - this->p2 = new GbPoint3D(0.0, 0.0, 0.0); - this->p1->addObserver(this); - this->p2->addObserver(this); + this->setName("cuboid"); + this->p1 = new GbPoint3D(0.0, 0.0, 0.0); + this->p2 = new GbPoint3D(0.0, 0.0, 0.0); + this->p1->addObserver(this); + this->p2->addObserver(this); } /*=======================================================*/ -GbCuboid3D::GbCuboid3D(const double& x1a,const double& x2a, const double& x3a, const double& x1b,const double& x2b, const double& x3b):GbObject3D() +GbCuboid3D::GbCuboid3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, const double &x2b, + const double &x3b) + : GbObject3D() { - this->setName("cuboid"); - this->p1 = new GbPoint3D(x1a, x2a, x3a); - this->p1->addObserver(this); - this->p2 = new GbPoint3D(x1b, x2b, x3b); - this->p2->addObserver(this); + this->setName("cuboid"); + this->p1 = new GbPoint3D(x1a, x2a, x3a); + this->p1->addObserver(this); + this->p2 = new GbPoint3D(x1b, x2b, x3b); + this->p2->addObserver(this); } /*=======================================================*/ -GbCuboid3D::GbCuboid3D(GbPoint3D* p1, GbPoint3D* p2) : GbObject3D() +GbCuboid3D::GbCuboid3D(GbPoint3D *p1, GbPoint3D *p2) : GbObject3D() { - this->setName("cuboid"); - if(!p1 || !p2) throw UbException(UB_EXARGS,"one point ==NULL"); - this->p1 = p1; - this->p1->addObserver(this); - this->p2 = p2; - this->p2->addObserver(this); + this->setName("cuboid"); + if (!p1 || !p2) + throw UbException(UB_EXARGS, "one point ==NULL"); + this->p1 = p1; + this->p1->addObserver(this); + this->p2 = p2; + this->p2->addObserver(this); } /*=======================================================*/ -GbCuboid3D::GbCuboid3D(GbCuboid3D* cuboid) : GbObject3D() +GbCuboid3D::GbCuboid3D(GbCuboid3D *cuboid) : GbObject3D() { - this->setName("cuboid"); - if(!cuboid->getPoint1() || !cuboid->getPoint2()) throw UbException(UB_EXARGS,"cuboid ==NULL"); - this->p1 = cuboid->getPoint1()->clone(); - this->p1->addObserver(this); - this->p2 = cuboid->getPoint2()->clone(); - this->p2->addObserver(this); + this->setName("cuboid"); + if (!cuboid->getPoint1() || !cuboid->getPoint2()) + throw UbException(UB_EXARGS, "cuboid ==NULL"); + this->p1 = cuboid->getPoint1()->clone(); + this->p1->addObserver(this); + this->p2 = cuboid->getPoint2()->clone(); + this->p2->addObserver(this); } /*=======================================================*/ // Destruktor GbCuboid3D::~GbCuboid3D() { - //cout<<"~GbCuboid3D()"<<endl; - if(this->p1) this->p1->removeObserver(this); - if(this->p2) this->p2->removeObserver(this); + // cout<<"~GbCuboid3D()"<<endl; + if (this->p1) + this->p1->removeObserver(this); + if (this->p2) + this->p2->removeObserver(this); } /*=======================================================*/ -void GbCuboid3D::finalize() -{ - if(this->p1) - { - this->p1->removeObserver(this); - this->p1->finalize(); - delete this->p1; - this->p1=NULL; - } - if(this->p2) - { - this->p2->removeObserver(this); - this->p2->finalize(); - delete this->p2; - this->p2=NULL; - } +void GbCuboid3D::finalize() +{ + if (this->p1) { + this->p1->removeObserver(this); + this->p1->finalize(); + delete this->p1; + this->p1 = NULL; + } + if (this->p2) { + this->p2->removeObserver(this); + this->p2->finalize(); + delete this->p2; + this->p2 = NULL; + } } /*=======================================================*/ -void GbCuboid3D::setPoint1(GbPoint3D* point1) -{ - if(this->p1) this->p1->removeObserver(this); - this->p1 = point1; - this->p1->addObserver(this); +void GbCuboid3D::setPoint1(GbPoint3D *point1) +{ + if (this->p1) + this->p1->removeObserver(this); + this->p1 = point1; + this->p1->addObserver(this); - this->notifyObserversObjectChanged(); + this->notifyObserversObjectChanged(); } /*=======================================================*/ -void GbCuboid3D::setPoint2(GbPoint3D* point2) -{ - if(this->p2) this->p2->removeObserver(this); - this->p2 = point2; - this->p2->addObserver(this); +void GbCuboid3D::setPoint2(GbPoint3D *point2) +{ + if (this->p2) + this->p2->removeObserver(this); + this->p2 = point2; + this->p2->addObserver(this); - this->notifyObserversObjectChanged(); + this->notifyObserversObjectChanged(); } /*=======================================================*/ -void GbCuboid3D::setPoints(GbPoint3D* point1, GbPoint3D* point2) -{ - if(this->p1) this->p1->removeObserver(this); - if(this->p2) this->p2->removeObserver(this); +void GbCuboid3D::setPoints(GbPoint3D *point1, GbPoint3D *point2) +{ + if (this->p1) + this->p1->removeObserver(this); + if (this->p2) + this->p2->removeObserver(this); - this->p1 = point1; - this->p2 = point2; + this->p1 = point1; + this->p2 = point2; - this->p1->addObserver(this); - this->p2->addObserver(this); + this->p1->addObserver(this); + this->p2->addObserver(this); - this->notifyObserversObjectChanged(); + this->notifyObserversObjectChanged(); } /*=======================================================*/ -void GbCuboid3D::setCenterCoordinates(const double& x1, const double& x2, const double& x3) +void GbCuboid3D::setCenterCoordinates(const double &x1, const double &x2, const double &x3) { - this->translate(x1-getX1Centroid(), x2-getX2Centroid(), x3-getX3Centroid() ); + this->translate(x1 - getX1Centroid(), x2 - getX2Centroid(), x3 - getX3Centroid()); } /*=======================================================*/ -double GbCuboid3D::getX1Centroid() -{ - return (0.5*(p1->x1 + p2->x1)); -} +double GbCuboid3D::getX1Centroid() { return (0.5 * (p1->x1 + p2->x1)); } /*=======================================================*/ -double GbCuboid3D::getX1Minimum() -{ - return (this->p1->x1 < this->p2->x1 ? this->p1->x1 : this->p2->x1); -} +double GbCuboid3D::getX1Minimum() { return (this->p1->x1 < this->p2->x1 ? this->p1->x1 : this->p2->x1); } /*=======================================================*/ -double GbCuboid3D::getX1Maximum() -{ - return (this->p1->x1 > this->p2->x1 ? this->p1->x1 : this->p2->x1); -} +double GbCuboid3D::getX1Maximum() { return (this->p1->x1 > this->p2->x1 ? this->p1->x1 : this->p2->x1); } /*=======================================================*/ -double GbCuboid3D::getX2Centroid() -{ - return (0.5*(p1->x2 + p2->x2)); -} +double GbCuboid3D::getX2Centroid() { return (0.5 * (p1->x2 + p2->x2)); } /*=======================================================*/ -double GbCuboid3D::getX2Minimum() -{ - return (this->p1->x2 < this->p2->x2 ? this->p1->x2 : this->p2->x2); -} +double GbCuboid3D::getX2Minimum() { return (this->p1->x2 < this->p2->x2 ? this->p1->x2 : this->p2->x2); } /*=======================================================*/ -double GbCuboid3D::getX2Maximum() -{ - return ( this->p1->x2 > this->p2->x2 ? this->p1->x2 : this->p2->x2); -} +double GbCuboid3D::getX2Maximum() { return (this->p1->x2 > this->p2->x2 ? this->p1->x2 : this->p2->x2); } /*=======================================================*/ -double GbCuboid3D::getX3Centroid() -{ - return (0.5*(p1->x3 + p2->x3)); -} +double GbCuboid3D::getX3Centroid() { return (0.5 * (p1->x3 + p2->x3)); } /*=======================================================*/ -double GbCuboid3D::getX3Minimum() -{ - return (this->p1->x3 < this->p2->x3 ? this->p1->x3 : this->p2->x3); -} +double GbCuboid3D::getX3Minimum() { return (this->p1->x3 < this->p2->x3 ? this->p1->x3 : this->p2->x3); } /*=======================================================*/ -double GbCuboid3D::getX3Maximum() -{ - return (this->p1->x3 > this->p2->x3 ? this->p1->x3 : this->p2->x3); -} +double GbCuboid3D::getX3Maximum() { return (this->p1->x3 > this->p2->x3 ? this->p1->x3 : this->p2->x3); } /*=======================================================*/ -double GbCuboid3D::getLengthX1() -{ - return (this->getX1Maximum() - this->getX1Minimum() ); -} +double GbCuboid3D::getLengthX1() { return (this->getX1Maximum() - this->getX1Minimum()); } /*=======================================================*/ -double GbCuboid3D::getLengthX2() -{ - return (this->getX2Maximum() - this->getX2Minimum()); -} +double GbCuboid3D::getLengthX2() { return (this->getX2Maximum() - this->getX2Minimum()); } /*=======================================================*/ -double GbCuboid3D::getLengthX3() -{ - return (this->getX3Maximum() - this->getX3Minimum()); -} +double GbCuboid3D::getLengthX3() { return (this->getX3Maximum() - this->getX3Minimum()); } /*=======================================================*/ -bool GbCuboid3D::isPointInGbObject3D(const double& x1p, const double& x2p, const double& x3p) +bool GbCuboid3D::isPointInGbObject3D(const double &x1p, const double &x2p, const double &x3p) { - //true, wenn 'in Object' oder 'auf Boundary'! - if (UbMath::less(x1p,this->getX1Minimum())) return false; - else if(UbMath::less(x2p,this->getX2Minimum())) return false; - else if(UbMath::less(x3p,this->getX3Minimum())) return false; - else if(UbMath::greater(x1p,this->getX1Maximum())) return false; - else if(UbMath::greater(x2p,this->getX2Maximum())) return false; - else if(UbMath::greater(x3p,this->getX3Maximum())) return false; - - return true; -} -/*=======================================================*/ -bool GbCuboid3D::isPointInGbObject3D(const double& x1p, const double& x2p, const double& x3p, bool& pointIsOnBoundary) + // true, wenn 'in Object' oder 'auf Boundary'! + if (UbMath::less(x1p, this->getX1Minimum())) + return false; + else if (UbMath::less(x2p, this->getX2Minimum())) + return false; + else if (UbMath::less(x3p, this->getX3Minimum())) + return false; + else if (UbMath::greater(x1p, this->getX1Maximum())) + return false; + else if (UbMath::greater(x2p, this->getX2Maximum())) + return false; + else if (UbMath::greater(x3p, this->getX3Maximum())) + return false; + + return true; +} +/*=======================================================*/ +bool GbCuboid3D::isPointInGbObject3D(const double &x1p, const double &x2p, const double &x3p, bool &pointIsOnBoundary) { - pointIsOnBoundary = false; - - //true, wenn 'in Object' oder 'auf Boundary'! - if (UbMath::less(x1p,this->getX1Minimum())) return false; - else if(UbMath::less(x2p,this->getX2Minimum())) return false; - else if(UbMath::less(x3p,this->getX3Minimum())) return false; - else if(UbMath::greater(x1p,this->getX1Maximum())) return false; - else if(UbMath::greater(x2p,this->getX2Maximum())) return false; - else if(UbMath::greater(x3p,this->getX3Maximum())) return false; - - if (UbMath::equal(x1p,this->getX1Minimum())) pointIsOnBoundary = true; - else if(UbMath::equal(x2p,this->getX2Minimum())) pointIsOnBoundary = true; - else if(UbMath::equal(x3p,this->getX3Minimum())) pointIsOnBoundary = true; - else if(UbMath::equal(x1p,this->getX1Maximum())) pointIsOnBoundary = true; - else if(UbMath::equal(x2p,this->getX2Maximum())) pointIsOnBoundary = true; - else if(UbMath::equal(x3p,this->getX3Maximum())) pointIsOnBoundary = true; - - return true; -} -/*=======================================================*/ -bool GbCuboid3D::isCellInsideGbObject3D(const double& x1p1,const double& x2p1,const double& x3p1,const double& x1p2,const double& x2p2,const double& x3p2) + pointIsOnBoundary = false; + + // true, wenn 'in Object' oder 'auf Boundary'! + if (UbMath::less(x1p, this->getX1Minimum())) + return false; + else if (UbMath::less(x2p, this->getX2Minimum())) + return false; + else if (UbMath::less(x3p, this->getX3Minimum())) + return false; + else if (UbMath::greater(x1p, this->getX1Maximum())) + return false; + else if (UbMath::greater(x2p, this->getX2Maximum())) + return false; + else if (UbMath::greater(x3p, this->getX3Maximum())) + return false; + + if (UbMath::equal(x1p, this->getX1Minimum())) + pointIsOnBoundary = true; + else if (UbMath::equal(x2p, this->getX2Minimum())) + pointIsOnBoundary = true; + else if (UbMath::equal(x3p, this->getX3Minimum())) + pointIsOnBoundary = true; + else if (UbMath::equal(x1p, this->getX1Maximum())) + pointIsOnBoundary = true; + else if (UbMath::equal(x2p, this->getX2Maximum())) + pointIsOnBoundary = true; + else if (UbMath::equal(x3p, this->getX3Maximum())) + pointIsOnBoundary = true; + + return true; +} +/*=======================================================*/ +bool GbCuboid3D::isCellInsideGbObject3D(const double &x1p1, const double &x2p1, const double &x3p1, const double &x1p2, + const double &x2p2, const double &x3p2) { - if ( UbMath::less (x1p1, this->getX1Minimum() ) ) return false; - else if( UbMath::less (x2p1, this->getX2Minimum() ) ) return false; - else if( UbMath::less (x3p1, this->getX3Minimum() ) ) return false; - else if( UbMath::greater(x1p2, this->getX1Maximum() ) ) return false; - else if( UbMath::greater(x2p2, this->getX2Maximum() ) ) return false; - else if( UbMath::greater(x3p2, this->getX3Maximum() ) ) return false; - - return true; -} -/*=======================================================*/ -bool GbCuboid3D::isCellCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) -//Merksatz: cell oder deren Volumen schneidet oder beinhaltet komplette oder Teile der CuboidUmrandung -//returns true: + if (UbMath::less(x1p1, this->getX1Minimum())) + return false; + else if (UbMath::less(x2p1, this->getX2Minimum())) + return false; + else if (UbMath::less(x3p1, this->getX3Minimum())) + return false; + else if (UbMath::greater(x1p2, this->getX1Maximum())) + return false; + else if (UbMath::greater(x2p2, this->getX2Maximum())) + return false; + else if (UbMath::greater(x3p2, this->getX3Maximum())) + return false; + + return true; +} +/*=======================================================*/ +bool GbCuboid3D::isCellCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b) +// Merksatz: cell oder deren Volumen schneidet oder beinhaltet komplette oder Teile der CuboidUmrandung +// returns true: // - cell cuts cuboid3D // - cell boxes cuboid3D -//returns false: +// returns false: // - cell completely inside cuboid3D ( = cuboid3D boxes cell) // - cell und cuboid3D haben kein gemeinsames Volumen { - //erstmal die dumm Loesung - if( !this->isCellInsideGbObject3D(x1a,x2a,x3a,x1b,x2b,x3b) - && this->isCellInsideOrCuttingGbObject3D(x1a,x2a,x3a,x1b,x2b,x3b) ) - { - return true; - } - - return false; - - //GbCuboid3D* cube = GbSystem3D::clipRectangle3D(*this->p1, *this->p2, x1a,x2a,x3a,x1b,x2b,x3b); - //if(cube) - //{ - // cube->finalize(); - // delete cube; - // return true; - //} - - //return false; + // erstmal die dumm Loesung + if (!this->isCellInsideGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b) && + this->isCellInsideOrCuttingGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b)) { + return true; + } + + return false; + + // GbCuboid3D* cube = GbSystem3D::clipRectangle3D(*this->p1, *this->p2, x1a,x2a,x3a,x1b,x2b,x3b); + // if(cube) + //{ + // cube->finalize(); + // delete cube; + // return true; + //} + + // return false; } /*=======================================================*/ -bool GbCuboid3D::isCellInsideOrCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) -//returns true: +bool GbCuboid3D::isCellInsideOrCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, + const double &x1b, const double &x2b, const double &x3b) +// returns true: // - cell completely inside cuboid3D ( = cuboid3D boxes cell) // - cell cuts cuboid3D // - cell boxes cuboid3D -//returns false: +// returns false: // - cell und cuboid3D haben kein gemeinsames Volumen { - //simpler check, da unser GbCuboid3D ein AABB is: - // anfA midA endA anfB midB endB - // | x<-- dxA -->| |<-dxB->x | - // |<----------------- T --------------->| - //ist |T| <= dxA + dxB -> overlap! - - if( UbMath::lessEqual( std::fabs( this->getX1Centroid() - 0.5*(x1b+x1a) /*Tx1*/ ) - , 0.5*( this->getLengthX1() + std::fabs(x1b-x1a) /*dx1A+dx1B*/) ) - - && UbMath::lessEqual( std::fabs( this->getX2Centroid() - 0.5*(x2b+x2a) /*Tx2*/ ) - , 0.5*( this->getLengthX2() + std::fabs(x2b-x2a) /*dx2A+dx2B*/) ) - - && UbMath::lessEqual( std::fabs( this->getX3Centroid() - 0.5*(x3b+x3a) /*Tx3*/ ) - , 0.5*( this->getLengthX3() + std::fabs(x3b-x3a) /*dx3A+dx3B*/) ) ) - { - return true; + // simpler check, da unser GbCuboid3D ein AABB is: + // anfA midA endA anfB midB endB + // | x<-- dxA -->| |<-dxB->x | + // |<----------------- T --------------->| + // ist |T| <= dxA + dxB -> overlap! + + if (UbMath::lessEqual(std::fabs(this->getX1Centroid() - 0.5 * (x1b + x1a) /*Tx1*/), + 0.5 * (this->getLengthX1() + std::fabs(x1b - x1a) /*dx1A+dx1B*/)) + + && UbMath::lessEqual(std::fabs(this->getX2Centroid() - 0.5 * (x2b + x2a) /*Tx2*/), + 0.5 * (this->getLengthX2() + std::fabs(x2b - x2a) /*dx2A+dx2B*/)) + + && UbMath::lessEqual(std::fabs(this->getX3Centroid() - 0.5 * (x3b + x3a) /*Tx3*/), + 0.5 * (this->getLengthX3() + std::fabs(x3b - x3a) /*dx3A+dx3B*/))) { + return true; } return false; // if( this->isCellInsideGbObject3D(x1a,x2a,x3a,x1b,x2b,x3b) - // || this->isCellCuttingGbObject3D(x1a,x2a,x3a,x1b,x2b,x3b) ) return true; - // - //return false; + // || this->isCellCuttingGbObject3D(x1a,x2a,x3a,x1b,x2b,x3b) ) return true; + // + // return false; } /*=======================================================*/ -vector<GbTriangle3D*> GbCuboid3D::getSurfaceTriangleSet() +vector<GbTriangle3D *> GbCuboid3D::getSurfaceTriangleSet() { - vector<GbTriangle3D*> triangles; - GbPoint3D p1(getX1Minimum(),getX2Minimum(),getX3Minimum()); - GbPoint3D p2(getX1Maximum(),getX2Minimum(),getX3Minimum()); - GbPoint3D p3(getX1Maximum(),getX2Maximum(),getX3Minimum()); - GbPoint3D p4(getX1Minimum(),getX2Maximum(),getX3Minimum()); - GbPoint3D p5(getX1Minimum(),getX2Minimum(),getX3Maximum()); - GbPoint3D p6(getX1Maximum(),getX2Minimum(),getX3Maximum()); - GbPoint3D p7(getX1Maximum(),getX2Maximum(),getX3Maximum()); - GbPoint3D p8(getX1Minimum(),getX2Maximum(),getX3Maximum()); - - GbPoint3D pUnten(getX1Centroid(),getX2Centroid(),getX3Minimum()); - GbPoint3D pOben(getX1Centroid(),getX2Centroid(),getX3Maximum()); - GbPoint3D pLinks(getX1Minimum(), getX2Centroid(),getX3Centroid()); - GbPoint3D pRechts(getX1Maximum(), getX2Centroid(),getX3Centroid()); - GbPoint3D pVorne(getX1Centroid(),getX2Minimum(),getX3Centroid()); - GbPoint3D pHinten(getX1Centroid(),getX2Maximum(),getX3Centroid()); - - //"unten" - triangles.push_back(new GbTriangle3D(new GbPoint3D(p2),new GbPoint3D(pUnten),new GbPoint3D(p3))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p2),new GbPoint3D(p1),new GbPoint3D(pUnten))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p3),new GbPoint3D(pUnten),new GbPoint3D(p4))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p1),new GbPoint3D(p4),new GbPoint3D(pUnten))); - //"oben" - triangles.push_back(new GbTriangle3D(new GbPoint3D(p5),new GbPoint3D(p6),new GbPoint3D(pOben))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p6),new GbPoint3D(p7),new GbPoint3D(pOben))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p5),new GbPoint3D(pOben),new GbPoint3D(p8))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(pOben),new GbPoint3D(p7),new GbPoint3D(p8))); - //"links" - triangles.push_back(new GbTriangle3D(new GbPoint3D(p4),new GbPoint3D(p1),new GbPoint3D(pLinks))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p4),new GbPoint3D(pLinks),new GbPoint3D(p8))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p8),new GbPoint3D(pLinks),new GbPoint3D(p5))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(pLinks),new GbPoint3D(p1),new GbPoint3D(p5))); - //"rechts" - triangles.push_back(new GbTriangle3D(new GbPoint3D(p2),new GbPoint3D(p3),new GbPoint3D(pRechts))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(pRechts),new GbPoint3D(p3),new GbPoint3D(p7))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p2),new GbPoint3D(pRechts),new GbPoint3D(p6))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(pRechts),new GbPoint3D(p7),new GbPoint3D(p6))); - //"hinten" - triangles.push_back(new GbTriangle3D(new GbPoint3D(p3),new GbPoint3D(p4),new GbPoint3D(pHinten))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p3),new GbPoint3D(pHinten),new GbPoint3D(p7))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p7),new GbPoint3D(pHinten),new GbPoint3D(p8))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(pHinten),new GbPoint3D(p4),new GbPoint3D(p8))); - //"vorne" - triangles.push_back(new GbTriangle3D(new GbPoint3D(p1),new GbPoint3D(p2),new GbPoint3D(pVorne))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(pVorne),new GbPoint3D(p2),new GbPoint3D(p6))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(p1),new GbPoint3D(pVorne),new GbPoint3D(p5))); - triangles.push_back(new GbTriangle3D(new GbPoint3D(pVorne),new GbPoint3D(p6),new GbPoint3D(p5))); - return triangles; -} -/*=======================================================*/ -void GbCuboid3D::addSurfaceTriangleSet(vector<UbTupleFloat3>& nodes, vector<UbTupleInt3>& triangles) + vector<GbTriangle3D *> triangles; + GbPoint3D p1(getX1Minimum(), getX2Minimum(), getX3Minimum()); + GbPoint3D p2(getX1Maximum(), getX2Minimum(), getX3Minimum()); + GbPoint3D p3(getX1Maximum(), getX2Maximum(), getX3Minimum()); + GbPoint3D p4(getX1Minimum(), getX2Maximum(), getX3Minimum()); + GbPoint3D p5(getX1Minimum(), getX2Minimum(), getX3Maximum()); + GbPoint3D p6(getX1Maximum(), getX2Minimum(), getX3Maximum()); + GbPoint3D p7(getX1Maximum(), getX2Maximum(), getX3Maximum()); + GbPoint3D p8(getX1Minimum(), getX2Maximum(), getX3Maximum()); + + GbPoint3D pUnten(getX1Centroid(), getX2Centroid(), getX3Minimum()); + GbPoint3D pOben(getX1Centroid(), getX2Centroid(), getX3Maximum()); + GbPoint3D pLinks(getX1Minimum(), getX2Centroid(), getX3Centroid()); + GbPoint3D pRechts(getX1Maximum(), getX2Centroid(), getX3Centroid()); + GbPoint3D pVorne(getX1Centroid(), getX2Minimum(), getX3Centroid()); + GbPoint3D pHinten(getX1Centroid(), getX2Maximum(), getX3Centroid()); + + //"unten" + triangles.push_back(new GbTriangle3D(new GbPoint3D(p2), new GbPoint3D(pUnten), new GbPoint3D(p3))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p2), new GbPoint3D(p1), new GbPoint3D(pUnten))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p3), new GbPoint3D(pUnten), new GbPoint3D(p4))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p1), new GbPoint3D(p4), new GbPoint3D(pUnten))); + //"oben" + triangles.push_back(new GbTriangle3D(new GbPoint3D(p5), new GbPoint3D(p6), new GbPoint3D(pOben))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p6), new GbPoint3D(p7), new GbPoint3D(pOben))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p5), new GbPoint3D(pOben), new GbPoint3D(p8))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(pOben), new GbPoint3D(p7), new GbPoint3D(p8))); + //"links" + triangles.push_back(new GbTriangle3D(new GbPoint3D(p4), new GbPoint3D(p1), new GbPoint3D(pLinks))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p4), new GbPoint3D(pLinks), new GbPoint3D(p8))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p8), new GbPoint3D(pLinks), new GbPoint3D(p5))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(pLinks), new GbPoint3D(p1), new GbPoint3D(p5))); + //"rechts" + triangles.push_back(new GbTriangle3D(new GbPoint3D(p2), new GbPoint3D(p3), new GbPoint3D(pRechts))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(pRechts), new GbPoint3D(p3), new GbPoint3D(p7))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p2), new GbPoint3D(pRechts), new GbPoint3D(p6))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(pRechts), new GbPoint3D(p7), new GbPoint3D(p6))); + //"hinten" + triangles.push_back(new GbTriangle3D(new GbPoint3D(p3), new GbPoint3D(p4), new GbPoint3D(pHinten))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p3), new GbPoint3D(pHinten), new GbPoint3D(p7))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p7), new GbPoint3D(pHinten), new GbPoint3D(p8))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(pHinten), new GbPoint3D(p4), new GbPoint3D(p8))); + //"vorne" + triangles.push_back(new GbTriangle3D(new GbPoint3D(p1), new GbPoint3D(p2), new GbPoint3D(pVorne))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(pVorne), new GbPoint3D(p2), new GbPoint3D(p6))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(p1), new GbPoint3D(pVorne), new GbPoint3D(p5))); + triangles.push_back(new GbTriangle3D(new GbPoint3D(pVorne), new GbPoint3D(p6), new GbPoint3D(p5))); + return triangles; +} +/*=======================================================*/ +void GbCuboid3D::addSurfaceTriangleSet(vector<UbTupleFloat3> &nodes, vector<UbTupleInt3> &triangles) { - /*0*/nodes.push_back( makeUbTuple((float)getX1Minimum(),(float)getX2Minimum(),(float)getX3Minimum())); - /*1*/nodes.push_back( makeUbTuple((float)getX1Maximum(),(float)getX2Minimum(),(float)getX3Minimum())); - /*2*/nodes.push_back( makeUbTuple((float)getX1Maximum(),(float)getX2Maximum(),(float)getX3Minimum())); - /*3*/nodes.push_back( makeUbTuple((float)getX1Minimum(),(float)getX2Maximum(),(float)getX3Minimum())); - - /*4*/nodes.push_back( makeUbTuple((float)getX1Minimum(),(float)getX2Minimum(),(float)getX3Maximum())); - /*5*/nodes.push_back( makeUbTuple((float)getX1Maximum(),(float)getX2Minimum(),(float)getX3Maximum())); - /*6*/nodes.push_back( makeUbTuple((float)getX1Maximum(),(float)getX2Maximum(),(float)getX3Maximum())); - /*7*/nodes.push_back( makeUbTuple((float)getX1Minimum(),(float)getX2Maximum(),(float)getX3Maximum())); - - //"unten" - triangles.push_back( makeUbTuple( 0, 1, 2) ); - triangles.push_back( makeUbTuple( 0, 2, 3) ); - //"oben" - triangles.push_back( makeUbTuple( 4, 5, 6) ); - triangles.push_back( makeUbTuple( 4, 6, 7) ); - //"links" - triangles.push_back( makeUbTuple( 0, 3, 7) ); - triangles.push_back( makeUbTuple( 0, 7, 4) ); - //"rechts" - triangles.push_back( makeUbTuple( 1, 2, 6) ); - triangles.push_back( makeUbTuple( 1, 6, 5) ); - //"hinten" - triangles.push_back( makeUbTuple( 3, 2, 7) ); - triangles.push_back( makeUbTuple( 2, 7, 6) ); - //"vorne" - triangles.push_back( makeUbTuple( 0, 1, 5) ); - triangles.push_back( makeUbTuple( 0, 5, 4) ); -} -/*=======================================================*/ -string GbCuboid3D::toString() + /*0*/ nodes.push_back(makeUbTuple((float)getX1Minimum(), (float)getX2Minimum(), (float)getX3Minimum())); + /*1*/ nodes.push_back(makeUbTuple((float)getX1Maximum(), (float)getX2Minimum(), (float)getX3Minimum())); + /*2*/ nodes.push_back(makeUbTuple((float)getX1Maximum(), (float)getX2Maximum(), (float)getX3Minimum())); + /*3*/ nodes.push_back(makeUbTuple((float)getX1Minimum(), (float)getX2Maximum(), (float)getX3Minimum())); + + /*4*/ nodes.push_back(makeUbTuple((float)getX1Minimum(), (float)getX2Minimum(), (float)getX3Maximum())); + /*5*/ nodes.push_back(makeUbTuple((float)getX1Maximum(), (float)getX2Minimum(), (float)getX3Maximum())); + /*6*/ nodes.push_back(makeUbTuple((float)getX1Maximum(), (float)getX2Maximum(), (float)getX3Maximum())); + /*7*/ nodes.push_back(makeUbTuple((float)getX1Minimum(), (float)getX2Maximum(), (float)getX3Maximum())); + + //"unten" + triangles.push_back(makeUbTuple(0, 1, 2)); + triangles.push_back(makeUbTuple(0, 2, 3)); + //"oben" + triangles.push_back(makeUbTuple(4, 5, 6)); + triangles.push_back(makeUbTuple(4, 6, 7)); + //"links" + triangles.push_back(makeUbTuple(0, 3, 7)); + triangles.push_back(makeUbTuple(0, 7, 4)); + //"rechts" + triangles.push_back(makeUbTuple(1, 2, 6)); + triangles.push_back(makeUbTuple(1, 6, 5)); + //"hinten" + triangles.push_back(makeUbTuple(3, 2, 7)); + triangles.push_back(makeUbTuple(2, 7, 6)); + //"vorne" + triangles.push_back(makeUbTuple(0, 1, 5)); + triangles.push_back(makeUbTuple(0, 5, 4)); +} +/*=======================================================*/ +string GbCuboid3D::toString() { - stringstream ss; - ss<<"GbCuboid3D["; - ss<<"p1="<<this->p1->toString(); - ss<<", p2="<<this->p2->toString(); - ss<<"]"; - return ss.str(); + stringstream ss; + ss << "GbCuboid3D["; + ss << "p1=" << this->p1->toString(); + ss << ", p2=" << this->p2->toString(); + ss << "]"; + return ss.str(); } /*=======================================================*/ -GbPoint3D* GbCuboid3D::calculateInterSectionPoint3D(GbPoint3D& /*point1*/, GbPoint3D& /*point2*/) +GbPoint3D *GbCuboid3D::calculateInterSectionPoint3D(GbPoint3D & /*point1*/, GbPoint3D & /*point2*/) { - throw UbException(UB_EXARGS,"not correct implemented"); + throw UbException(UB_EXARGS, "not correct implemented"); } /*=======================================================*/ -GbLine3D* GbCuboid3D::createClippedLine3D(GbPoint3D& point1, GbPoint3D& point2) +GbLine3D *GbCuboid3D::createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) { - return GbSystem3D::createClipLine3D(point1, point2, - p1->getX1Coordinate(),p1->getX2Coordinate(),p1->getX3Coordinate(), - p2->getX1Coordinate(),p2->getX2Coordinate(),p2->getX3Coordinate() ); + return GbSystem3D::createClipLine3D(point1, point2, p1->getX1Coordinate(), p1->getX2Coordinate(), + p1->getX3Coordinate(), p2->getX1Coordinate(), p2->getX2Coordinate(), + p2->getX3Coordinate()); } /*==========================================================*/ -void GbCuboid3D::objectChanged(UbObservable* changedObject) +void GbCuboid3D::objectChanged(UbObservable *changedObject) { - GbPoint3D* point = dynamic_cast<GbPoint3D*>(changedObject); - if(!point || (this->p1!=point && this->p2!=point)) return; + GbPoint3D *point = dynamic_cast<GbPoint3D *>(changedObject); + if (!point || (this->p1 != point && this->p2 != point)) + return; - this->notifyObserversObjectChanged(); + this->notifyObserversObjectChanged(); } /*==========================================================*/ -void GbCuboid3D::objectWillBeDeleted(UbObservable* objectForDeletion) +void GbCuboid3D::objectWillBeDeleted(UbObservable *objectForDeletion) { - if(this->p1) - { - UbObservable* observedObj = dynamic_cast<UbObservable*>(this->p1); - if(objectForDeletion == observedObj) { this->p1 = NULL; } - } - if(this->p2) - { - UbObservable* observedObj = dynamic_cast<UbObservable*>(this->p2); - if(objectForDeletion == observedObj) { this->p2 = NULL; } - } - //ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo + if (this->p1) { + UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p1); + if (objectForDeletion == observedObj) { + this->p1 = NULL; + } + } + if (this->p2) { + UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p2); + if (objectForDeletion == observedObj) { + this->p2 = NULL; + } + } + // ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo } /*=======================================================*/ -void GbCuboid3D::translate(const double& tx1, const double& tx2, const double& tx3) -{ - this->p1->translate(tx1, tx2, tx3); - this->p2->translate(tx1, tx2, tx3); - this->notifyObserversObjectChanged(); +void GbCuboid3D::translate(const double &tx1, const double &tx2, const double &tx3) +{ + this->p1->translate(tx1, tx2, tx3); + this->p2->translate(tx1, tx2, tx3); + this->notifyObserversObjectChanged(); } /*=======================================================*/ -void GbCuboid3D::scale(const double& sx1, const double& sx2, const double& sx3) -{ - double lenX1 = this->getLengthX1(); - double lenX2 = this->getLengthX2(); - double lenX3 = this->getLengthX3(); +void GbCuboid3D::scale(const double &sx1, const double &sx2, const double &sx3) +{ + double lenX1 = this->getLengthX1(); + double lenX2 = this->getLengthX2(); + double lenX3 = this->getLengthX3(); - double deltaX1 = lenX1*sx1 - lenX1; - double deltaX2 = lenX2*sx2 - lenX2; - double deltaX3 = lenX3*sx3 - lenX3; + double deltaX1 = lenX1 * sx1 - lenX1; + double deltaX2 = lenX2 * sx2 - lenX2; + double deltaX3 = lenX3 * sx3 - lenX3; - double p1X1 = this->p1->getX1Coordinate(); - double p1X2 = this->p1->getX2Coordinate(); - double p1X3 = this->p1->getX3Coordinate(); + double p1X1 = this->p1->getX1Coordinate(); + double p1X2 = this->p1->getX2Coordinate(); + double p1X3 = this->p1->getX3Coordinate(); - double p2X1 = this->p2->getX1Coordinate(); - double p2X2 = this->p2->getX2Coordinate(); - double p2X3 = this->p2->getX3Coordinate(); + double p2X1 = this->p2->getX1Coordinate(); + double p2X2 = this->p2->getX2Coordinate(); + double p2X3 = this->p2->getX3Coordinate(); - this->p1->setCoordinates(p1X1 - 0.5*deltaX1 - ,p1X2 - 0.5*deltaX2 - ,p1X3 - 0.5*deltaX3); + this->p1->setCoordinates(p1X1 - 0.5 * deltaX1, p1X2 - 0.5 * deltaX2, p1X3 - 0.5 * deltaX3); - this->p2->setCoordinates(p2X1 + 0.5*deltaX1 - ,p2X2 + 0.5*deltaX2 - ,p2X3 + 0.5*deltaX3); + this->p2->setCoordinates(p2X1 + 0.5 * deltaX1, p2X2 + 0.5 * deltaX2, p2X3 + 0.5 * deltaX3); } /*==========================================================*/ -double GbCuboid3D::getCellVolumeInsideGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) +double GbCuboid3D::getCellVolumeInsideGbObject3D(const double &x1a, const double &x2a, const double &x3a, + const double &x1b, const double &x2b, const double &x3b) { - if( this->isCellInsideGbObject3D(x1a,x2a,x3a,x1b,x2b,x3b) ) return 1.0*(x1b-x1a)*(x2b-x2a)*(x3b-x3a); - if( !(this->isCellCuttingGbObject3D(x1a,x2a,x3a,x1b,x2b,x3b)) ) return 0.0; - - GbCuboid3D* cube = GbSystem3D::clipRectangle3D(*this->p1, *this->p2, x1a,x2a,x3a,x1b,x2b,x3b); - - if(cube) - { - double eps; - eps = (cube->getLengthX1())*(cube->getLengthX2())*(cube->getLengthX3()); - cube->finalize(); - delete cube; - return eps; - } - return 0.0; + if (this->isCellInsideGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b)) + return 1.0 * (x1b - x1a) * (x2b - x2a) * (x3b - x3a); + if (!(this->isCellCuttingGbObject3D(x1a, x2a, x3a, x1b, x2b, x3b))) + return 0.0; + + GbCuboid3D *cube = GbSystem3D::clipRectangle3D(*this->p1, *this->p2, x1a, x2a, x3a, x1b, x2b, x3b); + + if (cube) { + double eps; + eps = (cube->getLengthX1()) * (cube->getLengthX2()) * (cube->getLengthX3()); + cube->finalize(); + delete cube; + return eps; + } + return 0.0; } /*==========================================================*/ -double GbCuboid3D::getIntersectionRaytraceFactor(const double& x1, const double& x2, const double& x3, const double& rx1, const double& rx2, const double& rx3) +double GbCuboid3D::getIntersectionRaytraceFactor(const double &x1, const double &x2, const double &x3, + const double &rx1, const double &rx2, const double &rx3) { - double minB[3] = { this->getX1Minimum(), this->getX2Minimum(), this->getX3Minimum() }; - double maxB[3] = { this->getX1Maximum(), this->getX2Maximum(), this->getX3Maximum() }; - double origin[3] = { x1, x2, x3 }; //point - double dir[3] = { rx1, rx2, rx3 }; //ray - - bool inside = true; - char quadrant[3]; - int whichPlane; - double maxT[3]; - double candidatePlane[3]; - - /* Find candidate planes; this loop can be avoided if - rays cast all from the eye(assume perpsective view) */ - for(int i=0; i<3; i++) - { - if(origin[i] < minB[i]) - { - quadrant[i] = 1/*LEFT*/; - candidatePlane[i] = minB[i]; - inside = false; - } - else if(origin[i] > maxB[i]) - { - quadrant[i] = 0/*RIGHT*/; - candidatePlane[i] = maxB[i]; - inside = false; - } - else - { - quadrant[i] = 2/*MIDDLE*/; - } - } - /* Ray origin inside bounding box */ - if(inside) - { - //throw UbException(UB_EXARGS,"not done"); - return 0.0; - } - - /* Calculate T distances to candidate planes */ - for(int i=0; i<3; i++) - { - if( quadrant[i]!=2/*MIDDLE*/ && fabs(dir[i])>1.E-10 ) - { - maxT[i] = (candidatePlane[i]-origin[i])/dir[i]; - } - else maxT[i] = -1.0; - } - - /* Get largest of the maxT's for final choice of intersection */ - whichPlane = 0; - for(int i=1; i<3; i++) - if (maxT[whichPlane] < maxT[i]) + double minB[3] = { this->getX1Minimum(), this->getX2Minimum(), this->getX3Minimum() }; + double maxB[3] = { this->getX1Maximum(), this->getX2Maximum(), this->getX3Maximum() }; + double origin[3] = { x1, x2, x3 }; // point + double dir[3] = { rx1, rx2, rx3 }; // ray + + bool inside = true; + char quadrant[3]; + int whichPlane; + double maxT[3]; + double candidatePlane[3]; + + /* Find candidate planes; this loop can be avoided if + rays cast all from the eye(assume perpsective view) */ + for (int i = 0; i < 3; i++) { + if (origin[i] < minB[i]) { + quadrant[i] = 1 /*LEFT*/; + candidatePlane[i] = minB[i]; + inside = false; + } else if (origin[i] > maxB[i]) { + quadrant[i] = 0 /*RIGHT*/; + candidatePlane[i] = maxB[i]; + inside = false; + } else { + quadrant[i] = 2 /*MIDDLE*/; + } + } + /* Ray origin inside bounding box */ + if (inside) { + // throw UbException(UB_EXARGS,"not done"); + return 0.0; + } + + /* Calculate T distances to candidate planes */ + for (int i = 0; i < 3; i++) { + if (quadrant[i] != 2 /*MIDDLE*/ && fabs(dir[i]) > 1.E-10) { + maxT[i] = (candidatePlane[i] - origin[i]) / dir[i]; + } else + maxT[i] = -1.0; + } + + /* Get largest of the maxT's for final choice of intersection */ + whichPlane = 0; + for (int i = 1; i < 3; i++) + if (maxT[whichPlane] < maxT[i]) whichPlane = i; - - /* Check final candidate actually inside box */ - if(maxT[whichPlane]< -1.E-10) return -1.0; - double dummy; - for(int i= 0; i<3; i++) - { - if( whichPlane!= i) - { - dummy = origin[i] + maxT[whichPlane]*dir[i]; - if(dummy < minB[i] || dummy > maxB[i]) - return -1.0; - } - } - - return maxT[whichPlane] ; /* ray hits box */ -} + /* Check final candidate actually inside box */ + if (maxT[whichPlane] < -1.E-10) + return -1.0; + double dummy; + for (int i = 0; i < 3; i++) { + if (whichPlane != i) { + dummy = origin[i] + maxT[whichPlane] * dir[i]; + if (dummy < minB[i] || dummy > maxB[i]) + return -1.0; + } + } + + return maxT[whichPlane]; /* ray hits box */ +} diff --git a/src/basics/geometry3d/GbCuboid3D.h b/src/basics/geometry3d/GbCuboid3D.h index 9a099737b..f0a0b0f98 100644 --- a/src/basics/geometry3d/GbCuboid3D.h +++ b/src/basics/geometry3d/GbCuboid3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,12 +33,12 @@ #ifndef GBCUBOID3D_H #define GBCUBOID3D_H -#include <vector> #include <cmath> +#include <vector> #include <GbPoint3D.h> -#include <basics/utilities/UbObserver.h> #include <basics/utilities/UbMath.h> +#include <basics/utilities/UbObserver.h> class GbLine3D; class GbObject3DCreator; @@ -50,96 +50,98 @@ using GbCuboid3DPtr = SPtr<GbCuboid3D>; //! \brief This Class provides basic 3D box objects. class GbCuboid3D : public GbObject3D, public UbObserver { -public: - GbCuboid3D(); - GbCuboid3D(const double& minX1,const double& minX2, const double& minX3, const double& maxX1,const double& maxX2, const double& maxX3); - GbCuboid3D(GbPoint3D *p1, GbPoint3D *p2); - GbCuboid3D(GbCuboid3D *cuboid); - ~GbCuboid3D() override; - - GbCuboid3D* clone() override { return new GbCuboid3D(this); } - void finalize() override; - - GbPoint3D* getPoint1() { return this->p1; } - GbPoint3D* getPoint2() { return this->p2; } - - void setPoint1(GbPoint3D* point1); - void setPoint2(GbPoint3D* point2); - void setPoints(GbPoint3D* point1, GbPoint3D* point2); - - double getX1Centroid() override; - double getX1Minimum() override; - double getX1Maximum() override; - double getX2Centroid() override; - double getX2Minimum() override; - double getX2Maximum() override; - double getX3Centroid() override; - double getX3Minimum() override; - double getX3Maximum() override; - void setCenterCoordinates(const double& x1, const double& x2, const double& x3) override; - - void translate(const double& x1, const double& x2, const double& x3) override; - void rotate(const double& rx1, const double& rx2, const double& rx3) override {} - void scale(const double& sx1, const double& sx2, const double& sx3) override; - - double getLengthX1(); - double getLengthX2(); - double getLengthX3(); - - bool isPointInGbObject3D(const double& x1p, const double& x2p, const double& x3p, bool& pointIsOnBoundary) override; - bool isPointInGbObject3D(const double& x1p, const double& x2p, const double& x3p) override; - bool isCellInsideGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) override; - bool isCellCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) override; - bool isCellInsideOrCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) override; - double getCellVolumeInsideGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) override; - - GbPoint3D* calculateInterSectionPoint3D(GbPoint3D& point1, GbPoint3D &point2); - //GbCuboid3D* createClippedRectangle3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b); - GbLine3D* createClippedLine3D(GbPoint3D& point1, GbPoint3D& point2) override; - - std::vector<GbTriangle3D*> getSurfaceTriangleSet() override; - void addSurfaceTriangleSet(std::vector<UbTupleFloat3>& nodes, std::vector<UbTupleInt3>& triangles) override; - - bool hasRaytracing() override { return true; } - /*|r| must be 1! einheitsvector!!*/ - double getIntersectionRaytraceFactor(const double& x1, const double& x2, const double& x3, const double& rx1, const double& rx2, const double& rx3) override; - - - double getDistance(GbPoint3D* p) - { - return this->getDistance( p->getX1Coordinate(), p->getX2Coordinate(), p->getX3Coordinate() ); - } - double getDistance(const double& x1p, const double& x2p, const double& x3p) - { - throw UbException( UB_EXARGS, "not implemented" ); - - // falls punkt innerhalt ist: minimalen abstand ausrechnen - if( this->isPointInGbObject3D(x1p,x2p,x3p) ) - { - double x1Dist = UbMath::min( std::abs(x1p-this->getX1Minimum()),std::abs(x1p-this->getX1Maximum()) ); - double x2Dist = UbMath::min( std::abs(x2p-this->getX2Minimum()),std::abs(x2p-this->getX2Maximum()) ); - double x3Dist = UbMath::min( std::abs(x3p-this->getX3Minimum()),std::abs(x3p-this->getX3Maximum()) ); - - return UbMath::min( x1Dist, x2Dist, x3Dist ); - } - else - { - - } - } - - std::string toString() override; - - //virtuelle Methoden von UbObserver - void objectChanged(UbObservable* changedObject) override; - void objectWillBeDeleted(UbObservable* objectForDeletion) override; - - - using GbObject3D::isPointInGbObject3D; //Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht ausprogrammieren, welche sonst hier "ueberdeckt" waere +public: + GbCuboid3D(); + GbCuboid3D(const double &minX1, const double &minX2, const double &minX3, const double &maxX1, const double &maxX2, + const double &maxX3); + GbCuboid3D(GbPoint3D *p1, GbPoint3D *p2); + GbCuboid3D(GbCuboid3D *cuboid); + ~GbCuboid3D() override; + + GbCuboid3D *clone() override { return new GbCuboid3D(this); } + void finalize() override; + + GbPoint3D *getPoint1() { return this->p1; } + GbPoint3D *getPoint2() { return this->p2; } + + void setPoint1(GbPoint3D *point1); + void setPoint2(GbPoint3D *point2); + void setPoints(GbPoint3D *point1, GbPoint3D *point2); + + double getX1Centroid() override; + double getX1Minimum() override; + double getX1Maximum() override; + double getX2Centroid() override; + double getX2Minimum() override; + double getX2Maximum() override; + double getX3Centroid() override; + double getX3Minimum() override; + double getX3Maximum() override; + void setCenterCoordinates(const double &x1, const double &x2, const double &x3) override; + + void translate(const double &x1, const double &x2, const double &x3) override; + void rotate(const double &rx1, const double &rx2, const double &rx3) override {} + void scale(const double &sx1, const double &sx2, const double &sx3) override; + + double getLengthX1(); + double getLengthX2(); + double getLengthX3(); + + bool isPointInGbObject3D(const double &x1p, const double &x2p, const double &x3p, bool &pointIsOnBoundary) override; + bool isPointInGbObject3D(const double &x1p, const double &x2p, const double &x3p) override; + bool isCellInsideGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b) override; + bool isCellCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b) override; + bool isCellInsideOrCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b) override; + double getCellVolumeInsideGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b) override; + + GbPoint3D *calculateInterSectionPoint3D(GbPoint3D &point1, GbPoint3D &point2); + // GbCuboid3D* createClippedRectangle3D(const double& x1a,const double& x2a,const double& x3a,const double& + // x1b,const double& x2b,const double& x3b); + GbLine3D *createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) override; + + std::vector<GbTriangle3D *> getSurfaceTriangleSet() override; + void addSurfaceTriangleSet(std::vector<UbTupleFloat3> &nodes, std::vector<UbTupleInt3> &triangles) override; + + bool hasRaytracing() override { return true; } + /*|r| must be 1! einheitsvector!!*/ + double getIntersectionRaytraceFactor(const double &x1, const double &x2, const double &x3, const double &rx1, + const double &rx2, const double &rx3) override; + + double getDistance(GbPoint3D *p) + { + return this->getDistance(p->getX1Coordinate(), p->getX2Coordinate(), p->getX3Coordinate()); + } + double getDistance(const double &x1p, const double &x2p, const double &x3p) + { + throw UbException(UB_EXARGS, "not implemented"); + + // falls punkt innerhalt ist: minimalen abstand ausrechnen + if (this->isPointInGbObject3D(x1p, x2p, x3p)) { + double x1Dist = UbMath::min(std::abs(x1p - this->getX1Minimum()), std::abs(x1p - this->getX1Maximum())); + double x2Dist = UbMath::min(std::abs(x2p - this->getX2Minimum()), std::abs(x2p - this->getX2Maximum())); + double x3Dist = UbMath::min(std::abs(x3p - this->getX3Minimum()), std::abs(x3p - this->getX3Maximum())); + + return UbMath::min(x1Dist, x2Dist, x3Dist); + } else { + } + } + + std::string toString() override; + + // virtuelle Methoden von UbObserver + void objectChanged(UbObservable *changedObject) override; + void objectWillBeDeleted(UbObservable *objectForDeletion) override; + + using GbObject3D::isPointInGbObject3D; // Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht + // ausprogrammieren, welche sonst hier "ueberdeckt" waere protected: - GbPoint3D* p1; - GbPoint3D* p2; + GbPoint3D *p1; + GbPoint3D *p2; }; -#endif +#endif diff --git a/src/basics/geometry3d/GbLine3D.cpp b/src/basics/geometry3d/GbLine3D.cpp index 752e3a421..d883de49a 100644 --- a/src/basics/geometry3d/GbLine3D.cpp +++ b/src/basics/geometry3d/GbLine3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,9 +30,9 @@ //! \ingroup geometry3d //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= +#include <GbCuboid3D.h> #include <GbLine3D.h> #include <GbSystem3D.h> -#include <GbCuboid3D.h> #include <GbTriangle3D.h> using namespace std; @@ -40,207 +40,232 @@ using namespace std; /*=======================================================*/ GbLine3D::GbLine3D() { - p1 = NULL; - p2 = NULL; - length = 0.0; + p1 = NULL; + p2 = NULL; + length = 0.0; } /*=======================================================*/ -GbLine3D::GbLine3D(GbPoint3D* point1, GbPoint3D* point2) +GbLine3D::GbLine3D(GbPoint3D *point1, GbPoint3D *point2) { - this->p1 = point1; - this->p2 = point2; - this->p1->addObserver(this); - this->p2->addObserver(this); - this->calculateValues(); + this->p1 = point1; + this->p2 = point2; + this->p1->addObserver(this); + this->p2->addObserver(this); + this->calculateValues(); } /*=======================================================*/ -GbLine3D::GbLine3D(GbLine3D* line) +GbLine3D::GbLine3D(GbLine3D *line) { - this->p1 = line->p1->clone(); - this->p2 = line->p2->clone(); - this->p1->addObserver(this); - this->p2->addObserver(this); - this->calculateValues(); + this->p1 = line->p1->clone(); + this->p2 = line->p2->clone(); + this->p1->addObserver(this); + this->p2->addObserver(this); + this->calculateValues(); } /*=======================================================*/ -GbLine3D::~GbLine3D() +GbLine3D::~GbLine3D() { - if(this->p1) this->p1->removeObserver(this); - if(this->p2) this->p2->removeObserver(this); + if (this->p1) + this->p1->removeObserver(this); + if (this->p2) + this->p2->removeObserver(this); } /*=======================================================*/ -void GbLine3D::finalize() -{ - if(this->p1) - { - this->p1->removeObserver(this); - this->p1->finalize(); - delete this->p1; - this->p1 = NULL; - } - if(this->p2) - { - this->p2->removeObserver(this); - this->p2->finalize(); - delete this->p2; - this->p2 = NULL; - } +void GbLine3D::finalize() +{ + if (this->p1) { + this->p1->removeObserver(this); + this->p1->finalize(); + delete this->p1; + this->p1 = NULL; + } + if (this->p2) { + this->p2->removeObserver(this); + this->p2->finalize(); + delete this->p2; + this->p2 = NULL; + } } /*=======================================================*/ -vector<GbTriangle3D*> GbLine3D::getSurfaceTriangleSet() +vector<GbTriangle3D *> GbLine3D::getSurfaceTriangleSet() { - vector<GbTriangle3D*> triangles; - GbPoint3D p1(getX1Minimum(),getX2Minimum(),getX3Minimum()); - GbPoint3D p2(getX1Centroid(),getX2Centroid(),getX3Centroid()); - GbPoint3D p3(getX1Maximum(),getX2Maximum(),getX3Maximum()); - - triangles.push_back(new GbTriangle3D(new GbPoint3D(p1),new GbPoint3D(p2),new GbPoint3D(p3))); - - return triangles; + vector<GbTriangle3D *> triangles; + GbPoint3D p1(getX1Minimum(), getX2Minimum(), getX3Minimum()); + GbPoint3D p2(getX1Centroid(), getX2Centroid(), getX3Centroid()); + GbPoint3D p3(getX1Maximum(), getX2Maximum(), getX3Maximum()); + + triangles.push_back(new GbTriangle3D(new GbPoint3D(p1), new GbPoint3D(p2), new GbPoint3D(p3))); + + return triangles; } /*=======================================================*/ -void GbLine3D::setPoint1(GbPoint3D* point1) -{ - if(this->p1) this->p1->removeObserver(this); - this->p1 = point1; - this->p1->addObserver(this); +void GbLine3D::setPoint1(GbPoint3D *point1) +{ + if (this->p1) + this->p1->removeObserver(this); + this->p1 = point1; + this->p1->addObserver(this); - if(this->p1 && this->p2) this->calculateValues(); + if (this->p1 && this->p2) + this->calculateValues(); } /*=======================================================*/ -void GbLine3D::setPoint2(GbPoint3D* point2) -{ - if(this->p2) this->p2->removeObserver(this); - this->p2 = point2; - this->p2->addObserver(this); +void GbLine3D::setPoint2(GbPoint3D *point2) +{ + if (this->p2) + this->p2->removeObserver(this); + this->p2 = point2; + this->p2->addObserver(this); - if(this->p1 && this->p2) this->calculateValues(); + if (this->p1 && this->p2) + this->calculateValues(); } /*=======================================================*/ -void GbLine3D::setPoints(GbPoint3D* point1, GbPoint3D* point2) -{ - if(this->p1) this->p1->removeObserver(this); - if(this->p2) this->p2->removeObserver(this); +void GbLine3D::setPoints(GbPoint3D *point1, GbPoint3D *point2) +{ + if (this->p1) + this->p1->removeObserver(this); + if (this->p2) + this->p2->removeObserver(this); - this->p1 = point1; - this->p2 = point2; + this->p1 = point1; + this->p2 = point2; - this->p1->addObserver(this); - this->p2->addObserver(this); + this->p1->addObserver(this); + this->p2->addObserver(this); - this->calculateValues(); + this->calculateValues(); } /*=======================================================*/ string GbLine3D::toString() { - stringstream ss; - ss<<"GbLine3D[p1="; - ss<<this->p1->toString()<<",p2="<<this->p2->toString()<<",l="<<this->getLength()<<"]"; - return(ss.str()); + stringstream ss; + ss << "GbLine3D[p1="; + ss << this->p1->toString() << ",p2=" << this->p2->toString() << ",l=" << this->getLength() << "]"; + return (ss.str()); } /*=======================================================*/ -GbPoint3D* GbLine3D::calculateIntersectionPoint3D(GbLine3D* /*line*/) +GbPoint3D *GbLine3D::calculateIntersectionPoint3D(GbLine3D * /*line*/) { - throw UbException(UB_EXARGS," not implemented"); - //return(GbSystem::calculateIntersectionPoint3D(*this->p1, *this->p2, *line->p1, *line->p2)); + throw UbException(UB_EXARGS, " not implemented"); + // return(GbSystem::calculateIntersectionPoint3D(*this->p1, *this->p2, *line->p1, *line->p2)); } /*======================================================================*/ -GbLine3D* GbLine3D::createClippedLine3D(GbCuboid3D* cuboid) +GbLine3D *GbLine3D::createClippedLine3D(GbCuboid3D *cuboid) { - return GbSystem3D::createClipLine3D(*this->p1, *this->p2, cuboid->getPoint1()->x1, cuboid->getPoint1()->x2, cuboid->getPoint1()->x3, cuboid->getPoint2()->x1, cuboid->getPoint2()->x2, cuboid->getPoint2()->x3); -} -/*======================================================================*/ -GbLine3D* GbLine3D::createClippedLine3D(GbPoint3D* pA, GbPoint3D* pE) -{ - return GbSystem3D::createClipLine3D(*this->p1, *this->p2, pA->x1, pA->x2, pA->x3, pE->x1, pE->x2, pE->x3); + return GbSystem3D::createClipLine3D(*this->p1, *this->p2, cuboid->getPoint1()->x1, cuboid->getPoint1()->x2, + cuboid->getPoint1()->x3, cuboid->getPoint2()->x1, cuboid->getPoint2()->x2, + cuboid->getPoint2()->x3); } /*======================================================================*/ -double GbLine3D::getDistance(const GbPoint3D& point) +GbLine3D *GbLine3D::createClippedLine3D(GbPoint3D *pA, GbPoint3D *pE) { - return this->getDistance(point.x1,point.x2,point.x3); + return GbSystem3D::createClipLine3D(*this->p1, *this->p2, pA->x1, pA->x2, pA->x3, pE->x1, pE->x2, pE->x3); } /*======================================================================*/ -double GbLine3D::getDistance(const double& x1,const double& x2,const double& x3) +double GbLine3D::getDistance(const GbPoint3D &point) { return this->getDistance(point.x1, point.x2, point.x3); } +/*======================================================================*/ +double GbLine3D::getDistance(const double &x1, const double &x2, const double &x3) { - double dx1 = this->p2->x1 - this->p1->x1; - double dx2 = this->p2->x2 - this->p1->x2; - double dx3 = this->p2->x3 - this->p1->x3; + double dx1 = this->p2->x1 - this->p1->x1; + double dx2 = this->p2->x2 - this->p1->x2; + double dx3 = this->p2->x3 - this->p1->x3; - //double vec[3]; - double a0 = x1 - p1->x1; - double a1 = x2 - p1->x2; - double a2 = x3 - p1->x3; + // double vec[3]; + double a0 = x1 - p1->x1; + double a1 = x2 - p1->x2; + double a2 = x3 - p1->x3; - double kreuzProd0 = a1 * dx3 - a2 * dx2; - double kreuzProd1 = a2 * dx1 - a0 * dx3; - double kreuzProd2 = a0 * dx2 - a1 * dx1; + double kreuzProd0 = a1 * dx3 - a2 * dx2; + double kreuzProd1 = a2 * dx1 - a0 * dx3; + double kreuzProd2 = a0 * dx2 - a1 * dx1; - return (std::sqrt(kreuzProd0*kreuzProd0+kreuzProd1*kreuzProd1+kreuzProd2*kreuzProd2))/length; + return (std::sqrt(kreuzProd0 * kreuzProd0 + kreuzProd1 * kreuzProd1 + kreuzProd2 * kreuzProd2)) / length; } /*=======================================================*/ void GbLine3D::calculateValues() { - double dx1 = this->p2->x1 - this->p1->x1; - double dx2 = this->p2->x2 - this->p1->x2; - double dx3 = this->p2->x3 - this->p1->x3; - this->length = std::sqrt(dx1*dx1+dx2*dx2+dx3*dx3); + double dx1 = this->p2->x1 - this->p1->x1; + double dx2 = this->p2->x2 - this->p1->x2; + double dx3 = this->p2->x3 - this->p1->x3; + this->length = std::sqrt(dx1 * dx1 + dx2 * dx2 + dx3 * dx3); } /*==========================================================*/ -void GbLine3D::objectChanged(UbObservable* changedObject) +void GbLine3D::objectChanged(UbObservable *changedObject) { - GbPoint3D* point = dynamic_cast<GbPoint3D*>(changedObject); - if(!point || (this->p1!=point && this->p2!=point)) return; + GbPoint3D *point = dynamic_cast<GbPoint3D *>(changedObject); + if (!point || (this->p1 != point && this->p2 != point)) + return; - this->calculateValues(); + this->calculateValues(); } /*==========================================================*/ -void GbLine3D::objectWillBeDeleted(UbObservable* objectForDeletion) -{ - if(this->p1) - { - UbObservable* observedObj = dynamic_cast<UbObservable*>(this->p1); - if(objectForDeletion == observedObj) { this->p1 = NULL; length = 0.0; } - } - if(this->p2) - { - UbObservable* observedObj = dynamic_cast<UbObservable*>(this->p2); - if(objectForDeletion == observedObj) { this->p2 = NULL; length = 0.0; } - } - //ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo +void GbLine3D::objectWillBeDeleted(UbObservable *objectForDeletion) +{ + if (this->p1) { + UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p1); + if (objectForDeletion == observedObj) { + this->p1 = NULL; + length = 0.0; + } + } + if (this->p2) { + UbObservable *observedObj = dynamic_cast<UbObservable *>(this->p2); + if (objectForDeletion == observedObj) { + this->p2 = NULL; + length = 0.0; + } + } + // ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo } /*==========================================================*/ -void GbLine3D::scale(const double& sx1, const double& sx2, const double& sx3) -{ - double p1X1 = this->p1->getX1Coordinate(); - double p1X2 = this->p1->getX2Coordinate(); - double p1X3 = this->p1->getX3Coordinate(); - - double p2X1 = this->p2->getX1Coordinate(); - double p2X2 = this->p2->getX2Coordinate(); - double p2X3 = this->p2->getX3Coordinate(); - - double lenX1 = fabs( p1X1 - p2X1 ); - double lenX2 = fabs( p1X2 - p2X2 ); - double lenX3 = fabs( p1X3 - p2X3 ); - - double deltaX1 = lenX1*sx1 - lenX1; - double deltaX2 = lenX2*sx2 - lenX2; - double deltaX3 = lenX3*sx3 - lenX3; - - if(p1X1<p2X1) { p1X1 -= 0.5*deltaX1; p2X1 += 0.5*deltaX1; } - else { p1X1 += 0.5*deltaX1; p2X1 -= 0.5*deltaX1; } - if(p1X2<p2X2) { p1X2 -= 0.5*deltaX2; p2X2 += 0.5*deltaX2; } - else { p1X2 += 0.5*deltaX2; p2X2 -= 0.5*deltaX2; } - if(p1X3<p2X3) { p1X3 -= 0.5*deltaX3; p2X3 += 0.5*deltaX3; } - else { p1X3 += 0.5*deltaX3; p2X3 -= 0.5*deltaX3; } - - this->p1->setCoordinates(p1X1,p1X2,p1X3); - this->p2->setCoordinates(p2X1,p2X2,p2X3); +void GbLine3D::scale(const double &sx1, const double &sx2, const double &sx3) +{ + double p1X1 = this->p1->getX1Coordinate(); + double p1X2 = this->p1->getX2Coordinate(); + double p1X3 = this->p1->getX3Coordinate(); + + double p2X1 = this->p2->getX1Coordinate(); + double p2X2 = this->p2->getX2Coordinate(); + double p2X3 = this->p2->getX3Coordinate(); + + double lenX1 = fabs(p1X1 - p2X1); + double lenX2 = fabs(p1X2 - p2X2); + double lenX3 = fabs(p1X3 - p2X3); + + double deltaX1 = lenX1 * sx1 - lenX1; + double deltaX2 = lenX2 * sx2 - lenX2; + double deltaX3 = lenX3 * sx3 - lenX3; + + if (p1X1 < p2X1) { + p1X1 -= 0.5 * deltaX1; + p2X1 += 0.5 * deltaX1; + } else { + p1X1 += 0.5 * deltaX1; + p2X1 -= 0.5 * deltaX1; + } + if (p1X2 < p2X2) { + p1X2 -= 0.5 * deltaX2; + p2X2 += 0.5 * deltaX2; + } else { + p1X2 += 0.5 * deltaX2; + p2X2 -= 0.5 * deltaX2; + } + if (p1X3 < p2X3) { + p1X3 -= 0.5 * deltaX3; + p2X3 += 0.5 * deltaX3; + } else { + p1X3 += 0.5 * deltaX3; + p2X3 -= 0.5 * deltaX3; + } + + this->p1->setCoordinates(p1X1, p1X2, p1X3); + this->p2->setCoordinates(p2X1, p2X2, p2X3); } /*=======================================================*/ -void GbLine3D::translate(const double& tx1, const double& tx2, const double& tx3) -{ - this->p1->translate(tx1, tx2, tx3); - this->p2->translate(tx1, tx2, tx3); - //this->notifyObserversObjectChanged(); +void GbLine3D::translate(const double &tx1, const double &tx2, const double &tx3) +{ + this->p1->translate(tx1, tx2, tx3); + this->p2->translate(tx1, tx2, tx3); + // this->notifyObserversObjectChanged(); } diff --git a/src/basics/geometry3d/GbLine3D.h b/src/basics/geometry3d/GbLine3D.h index 25697f59b..29e0a3740 100644 --- a/src/basics/geometry3d/GbLine3D.h +++ b/src/basics/geometry3d/GbLine3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,9 +33,9 @@ #ifndef GBLINE3D_H #define GBLINE3D_H -#include <sstream> #include <cmath> - +#include <sstream> + #include <basics/utilities/UbObserver.h> #include <GbObject3D.h> @@ -46,90 +46,114 @@ class GbCuboid3D; #include <PointerDefinitions.h> ////////////////////////////////////////////////////////////////////////// -//! +//! //! \class GbLine3D -//! +//! //! \brief This Class provides basic 3D line objects. //! \details The describing points are observed by 3D line objects. //! ////////////////////////////////////////////////////////////////////////// -class GbLine3D : public GbObject3D , public UbObserver +class GbLine3D : public GbObject3D, public UbObserver { public: - GbLine3D(); - GbLine3D(GbPoint3D* point1, GbPoint3D* point2); - GbLine3D(GbLine3D* line); - ~GbLine3D() override; - - GbLine3D* clone() override { return new GbLine3D(this); } - void finalize() override; - - void setPoint1(GbPoint3D* point1); - void setPoint2(GbPoint3D* point2); - void setPoints(GbPoint3D* point1, GbPoint3D* point2); - - void deletePoint1() { if(this->p1) {this->p1->removeObserver(this); delete this->p1; this->p1=NULL;} } - void deletePoint2() { if(this->p2) {this->p2->removeObserver(this); delete this->p2; this->p2=NULL;} } - void deletePoints() { this->deletePoint1(); this->deletePoint2(); } - - GbPoint3D* getPoint1() { return this->p1; } - GbPoint3D* getPoint2() { return this->p2; } - - double getLength() { return(this->length); } - - double getX1Centroid() override { return((this->p1->x1+this->p2->x1)*0.5);} - double getX2Centroid() override { return((this->p1->x2+this->p2->x2)*0.5); }; - double getX3Centroid() override { return((this->p1->x3+this->p2->x3)*0.5); } - - double getX1Minimum() override { return(this->p1->x1 < this->p2->x1 ? this->p1->x1 : this->p2->x1); } - double getX2Minimum() override { return(this->p1->x2 < this->p2->x2 ? this->p1->x2 : this->p2->x2); } - double getX3Minimum() override { return(this->p1->x3 < this->p2->x3 ? this->p1->x3 : this->p2->x3); } - - double getX1Maximum() override { return(this->p1->x1 > this->p2->x1 ? this->p1->x1 : this->p2->x1); } - double getX2Maximum() override { return(this->p1->x2 > this->p2->x2 ? this->p1->x2 : this->p2->x2); } - double getX3Maximum() override { return(this->p1->x3 > this->p2->x3 ? this->p1->x3 : this->p2->x3); } - - void scale(const double& sx1, const double& sx2, const double& sx3) override; - void translate(const double& tx1, const double& tx2, const double& tx3) override; - - GbPoint3D* calculateIntersectionPoint3D(GbLine3D* line); - GbLine3D* createClippedLine3D(GbCuboid3D* cuboid); - GbLine3D* createClippedLine3D(GbPoint3D* pA, GbPoint3D* pE); - - double getDistance(const GbPoint3D& point); - double getDistance(const double& x1,const double& x2,const double& x3); - - std::vector<GbTriangle3D*> getSurfaceTriangleSet() override; - bool isPointInGbObject3D(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/) override - { - throw UbException(UB_EXARGS,"not implemented"); - } - bool isPointInGbObject3D(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/, bool& /*pointIsOnBoundary*/) override - { - throw UbException(UB_EXARGS,"not implemented"); - } - bool isCellInsideGbObject3D(const double& /*x11*/,const double& /*x21*/,const double& /*x31*/,const double& /*x12*/,const double& /*x22*/,const double& /*x32*/) override { return false; } - - GbLine3D* createClippedLine3D (GbPoint3D& /*point1*/, GbPoint3D& /*point2*/) override - { - throw UbException(UB_EXARGS,"not implemented"); - } - - //virtuelle Methoden von UbObserver - void objectChanged(UbObservable* changedObject) override; - void objectWillBeDeleted(UbObservable* objectForDeletion) override; - - std::string toString() override; - - using GbObject3D::isPointInGbObject3D; //Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht ausprogrammieren, welche sonst hier "ueberdeckt" waere + GbLine3D(); + GbLine3D(GbPoint3D *point1, GbPoint3D *point2); + GbLine3D(GbLine3D *line); + ~GbLine3D() override; + + GbLine3D *clone() override { return new GbLine3D(this); } + void finalize() override; + + void setPoint1(GbPoint3D *point1); + void setPoint2(GbPoint3D *point2); + void setPoints(GbPoint3D *point1, GbPoint3D *point2); + + void deletePoint1() + { + if (this->p1) { + this->p1->removeObserver(this); + delete this->p1; + this->p1 = NULL; + } + } + void deletePoint2() + { + if (this->p2) { + this->p2->removeObserver(this); + delete this->p2; + this->p2 = NULL; + } + } + void deletePoints() + { + this->deletePoint1(); + this->deletePoint2(); + } + + GbPoint3D *getPoint1() { return this->p1; } + GbPoint3D *getPoint2() { return this->p2; } + + double getLength() { return (this->length); } + + double getX1Centroid() override { return ((this->p1->x1 + this->p2->x1) * 0.5); } + double getX2Centroid() override { return ((this->p1->x2 + this->p2->x2) * 0.5); }; + double getX3Centroid() override { return ((this->p1->x3 + this->p2->x3) * 0.5); } + + double getX1Minimum() override { return (this->p1->x1 < this->p2->x1 ? this->p1->x1 : this->p2->x1); } + double getX2Minimum() override { return (this->p1->x2 < this->p2->x2 ? this->p1->x2 : this->p2->x2); } + double getX3Minimum() override { return (this->p1->x3 < this->p2->x3 ? this->p1->x3 : this->p2->x3); } + + double getX1Maximum() override { return (this->p1->x1 > this->p2->x1 ? this->p1->x1 : this->p2->x1); } + double getX2Maximum() override { return (this->p1->x2 > this->p2->x2 ? this->p1->x2 : this->p2->x2); } + double getX3Maximum() override { return (this->p1->x3 > this->p2->x3 ? this->p1->x3 : this->p2->x3); } + + void scale(const double &sx1, const double &sx2, const double &sx3) override; + void translate(const double &tx1, const double &tx2, const double &tx3) override; + + GbPoint3D *calculateIntersectionPoint3D(GbLine3D *line); + GbLine3D *createClippedLine3D(GbCuboid3D *cuboid); + GbLine3D *createClippedLine3D(GbPoint3D *pA, GbPoint3D *pE); + + double getDistance(const GbPoint3D &point); + double getDistance(const double &x1, const double &x2, const double &x3); + + std::vector<GbTriangle3D *> getSurfaceTriangleSet() override; + bool isPointInGbObject3D(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/) override + { + throw UbException(UB_EXARGS, "not implemented"); + } + bool isPointInGbObject3D(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/, + bool & /*pointIsOnBoundary*/) override + { + throw UbException(UB_EXARGS, "not implemented"); + } + bool isCellInsideGbObject3D(const double & /*x11*/, const double & /*x21*/, const double & /*x31*/, + const double & /*x12*/, const double & /*x22*/, const double & /*x32*/) override + { + return false; + } + + GbLine3D *createClippedLine3D(GbPoint3D & /*point1*/, GbPoint3D & /*point2*/) override + { + throw UbException(UB_EXARGS, "not implemented"); + } + + // virtuelle Methoden von UbObserver + void objectChanged(UbObservable *changedObject) override; + void objectWillBeDeleted(UbObservable *objectForDeletion) override; + + std::string toString() override; + + using GbObject3D::isPointInGbObject3D; // Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht + // ausprogrammieren, welche sonst hier "ueberdeckt" waere protected: - GbPoint3D* p1; - GbPoint3D* p2; - double length; + GbPoint3D *p1; + GbPoint3D *p2; + double length; private: - void calculateValues(); + void calculateValues(); }; #endif diff --git a/src/basics/geometry3d/GbObject3D.cpp b/src/basics/geometry3d/GbObject3D.cpp index 1e96e72f3..b24831514 100644 --- a/src/basics/geometry3d/GbObject3D.cpp +++ b/src/basics/geometry3d/GbObject3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,84 +32,66 @@ //======================================================================================= #include <GbObject3D.h> #include <GbPoint3D.h> -#include <basics/utilities/UbMath.h> +#include <basics/utilities/UbMath.h> using namespace std; /*======================================================================*/ -bool GbObject3D::isPointInGbObject3D(GbPoint3D* p) +bool GbObject3D::isPointInGbObject3D(GbPoint3D *p) { - return this->isPointInGbObject3D(p->getX1Centroid(),p->getX2Coordinate(),p->getX3Coordinate()); -} + return this->isPointInGbObject3D(p->getX1Centroid(), p->getX2Coordinate(), p->getX3Coordinate()); +} /*======================================================================*/ -bool GbObject3D::isCellInsideGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) +bool GbObject3D::isCellInsideGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b) { - if( this->isPointInGbObject3D(x1a, x2a, x3a) - && this->isPointInGbObject3D(x1b, x2a, x3a) - && this->isPointInGbObject3D(x1b, x2b, x3a) - && this->isPointInGbObject3D(x1a, x2b, x3a) - && this->isPointInGbObject3D(x1a, x2a, x3b) - && this->isPointInGbObject3D(x1b, x2a, x3b) - && this->isPointInGbObject3D(x1b, x2b, x3b) - && this->isPointInGbObject3D(x1a, x2b, x3b)) - { - return true; - } + if (this->isPointInGbObject3D(x1a, x2a, x3a) && this->isPointInGbObject3D(x1b, x2a, x3a) && + this->isPointInGbObject3D(x1b, x2b, x3a) && this->isPointInGbObject3D(x1a, x2b, x3a) && + this->isPointInGbObject3D(x1a, x2a, x3b) && this->isPointInGbObject3D(x1b, x2a, x3b) && + this->isPointInGbObject3D(x1b, x2b, x3b) && this->isPointInGbObject3D(x1a, x2b, x3b)) { + return true; + } - return false; + return false; } /*======================================================================*/ -bool GbObject3D::isCellCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) +bool GbObject3D::isCellCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b) { - if( this->isPointInGbObject3D(x1a, x2a, x3a) - || this->isPointInGbObject3D(x1b, x2a, x3a) - || this->isPointInGbObject3D(x1b, x2b, x3a) - || this->isPointInGbObject3D(x1a, x2b, x3a) - || this->isPointInGbObject3D(x1a, x2a, x3b) - || this->isPointInGbObject3D(x1b, x2a, x3b) - || this->isPointInGbObject3D(x1b, x2b, x3b) - || this->isPointInGbObject3D(x1a, x2b, x3b) ) - { - if( !this->isPointInGbObject3D(x1a, x2a, x3a) - || !this->isPointInGbObject3D(x1b, x2a, x3a) - || !this->isPointInGbObject3D(x1b, x2b, x3a) - || !this->isPointInGbObject3D(x1a, x2b, x3a) - || !this->isPointInGbObject3D(x1a, x2a, x3b) - || !this->isPointInGbObject3D(x1b, x2a, x3b) - || !this->isPointInGbObject3D(x1b, x2b, x3b) - || !this->isPointInGbObject3D(x1a, x2b, x3b)) return true; - } - return false; + if (this->isPointInGbObject3D(x1a, x2a, x3a) || this->isPointInGbObject3D(x1b, x2a, x3a) || + this->isPointInGbObject3D(x1b, x2b, x3a) || this->isPointInGbObject3D(x1a, x2b, x3a) || + this->isPointInGbObject3D(x1a, x2a, x3b) || this->isPointInGbObject3D(x1b, x2a, x3b) || + this->isPointInGbObject3D(x1b, x2b, x3b) || this->isPointInGbObject3D(x1a, x2b, x3b)) { + if (!this->isPointInGbObject3D(x1a, x2a, x3a) || !this->isPointInGbObject3D(x1b, x2a, x3a) || + !this->isPointInGbObject3D(x1b, x2b, x3a) || !this->isPointInGbObject3D(x1a, x2b, x3a) || + !this->isPointInGbObject3D(x1a, x2a, x3b) || !this->isPointInGbObject3D(x1b, x2a, x3b) || + !this->isPointInGbObject3D(x1b, x2b, x3b) || !this->isPointInGbObject3D(x1a, x2b, x3b)) + return true; + } + return false; } /*======================================================================*/ -bool GbObject3D::isCellInsideOrCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b) +bool GbObject3D::isCellInsideOrCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, + const double &x1b, const double &x2b, const double &x3b) { - if( this->isPointInGbObject3D(x1a, x2a, x3a) - || this->isPointInGbObject3D(x1b, x2a, x3a) - || this->isPointInGbObject3D(x1b, x2b, x3a) - || this->isPointInGbObject3D(x1a, x2b, x3a) - || this->isPointInGbObject3D(x1a, x2a, x3b) - || this->isPointInGbObject3D(x1b, x2a, x3b) - || this->isPointInGbObject3D(x1b, x2b, x3b) - || this->isPointInGbObject3D(x1a, x2b, x3b)) - { - return true; - } + if (this->isPointInGbObject3D(x1a, x2a, x3a) || this->isPointInGbObject3D(x1b, x2a, x3a) || + this->isPointInGbObject3D(x1b, x2b, x3a) || this->isPointInGbObject3D(x1a, x2b, x3a) || + this->isPointInGbObject3D(x1a, x2a, x3b) || this->isPointInGbObject3D(x1b, x2a, x3b) || + this->isPointInGbObject3D(x1b, x2b, x3b) || this->isPointInGbObject3D(x1a, x2b, x3b)) { + return true; + } - return false; + return false; } /*=======================================================*/ -bool GbObject3D::isInsideCell(const double& minX1,const double& minX2,const double& minX3,const double& maxX1,const double& maxX2,const double& maxX3) +bool GbObject3D::isInsideCell(const double &minX1, const double &minX2, const double &minX3, const double &maxX1, + const double &maxX2, const double &maxX3) { - if( UbMath::greaterEqual(this->getX1Minimum(),minX1) - && UbMath::greaterEqual(this->getX2Minimum(),minX2) - && UbMath::greaterEqual(this->getX3Minimum(),minX3) - && UbMath::lessEqual(this->getX1Maximum(),maxX1) - && UbMath::lessEqual(this->getX2Maximum(),maxX2) - && UbMath::lessEqual(this->getX2Maximum(),maxX3) ) return true; + if (UbMath::greaterEqual(this->getX1Minimum(), minX1) && UbMath::greaterEqual(this->getX2Minimum(), minX2) && + UbMath::greaterEqual(this->getX3Minimum(), minX3) && UbMath::lessEqual(this->getX1Maximum(), maxX1) && + UbMath::lessEqual(this->getX2Maximum(), maxX2) && UbMath::lessEqual(this->getX2Maximum(), maxX3)) + return true; - return false; + return false; } - - diff --git a/src/basics/geometry3d/GbObject3D.h b/src/basics/geometry3d/GbObject3D.h index be2191811..f60e64c8f 100644 --- a/src/basics/geometry3d/GbObject3D.h +++ b/src/basics/geometry3d/GbObject3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -36,12 +36,11 @@ #include <string> #include <vector> - -#include <basics/utilities/UbSystem.h> +#include <basics/objects/ObObject.h> #include <basics/utilities/UbException.h> #include <basics/utilities/UbObservable.h> +#include <basics/utilities/UbSystem.h> #include <basics/utilities/UbTuple.h> -#include <basics/objects/ObObject.h> class GbPoint3D; class GbLine3D; @@ -51,99 +50,139 @@ class GbObject3DCreator; #include <PointerDefinitions.h> ////////////////////////////////////////////////////////////////////////// -//! +//! //! \class GbObject3D -//! +//! //! \brief This Interface provides basic 3D geometry objects methods. -//! +//! ////////////////////////////////////////////////////////////////////////// class GbObject3D : public ObObject { public: - //abstract Methods - virtual void finalize() = 0 ; //destroys also all dynamic objects (e.g. GbPoints in GbLine) - /** - * Returns the centroid x1 coordinate of this 3D object. - * @return the centroid x1 coordinate of this 3D object - */ - virtual double getX1Centroid()=0; - /** - * Returns the minimum x1 coordinate of this 3D object. - * @return the minimum x1 coordinate of this 3D object - */ - virtual double getX1Minimum()=0; - /** - * Returns the maximum x1 coordinate of this 3D object. - * @return the maximum x1 coordinate of this 3D object - */ - virtual double getX1Maximum()=0; - /** - * Returns the centroid x2 coordinate of this 3D object. - * @return the centroid x2 coordinate of this 3D object - */ - virtual double getX2Centroid()=0; - /** - * Returns the minimum x2 coordinate of this 3D object. - * @return the minimum x2 coordinate of this 3D object - */ - virtual double getX2Minimum()=0; - /** - * Returns the maximum x2 coordinate of this 3D object. - * @return the maximum x2 coordinate of this 3D object - */ - virtual double getX2Maximum()=0; - - virtual double getX3Centroid()=0; - /** - * Returns the minimum x2 coordinate of this 3D object. - * @return the minimum x2 coordinate of this 3D object - */ - virtual double getX3Minimum()=0; - /** - * Returns the maximum x2 coordinate of this 3D object. - * @return the maximum x2 coordinate of this 3D object - */ - virtual double getX3Maximum()=0; - - /*=======================================================*/ - double getLengthX1() { return (getX1Maximum()-getX1Minimum()); } - double getLengthX2() { return (getX2Maximum()-getX2Minimum()); } - double getLengthX3() { return (getX3Maximum()-getX3Minimum()); } - - virtual void setCenterX1Coordinate(const double& /*value*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual void setCenterX2Coordinate(const double& /*value*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual void setCenterX3Coordinate(const double& /*value*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual void setCenterCoordinates(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/) { throw UbException(UB_EXARGS, "not implemented for " + (std::string)typeid(*this).name()); } - virtual void setCenterCoordinates(const UbTupleDouble3& /*position*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - - //Rotates the Point in relation to the origen. - //Parameters must be radian measure. - virtual void rotate(const double& /*rx1*/, const double& /*rx2*/, const double& /*rx3*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual void translate(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - virtual void scale(const double& /*sx1*/, const double& /*sx2*/, const double& /*sx3*/) { throw UbException(UB_EXARGS,"not implemented for "+(std::string)typeid(*this).name() ); } - - virtual bool isPointInGbObject3D(GbPoint3D* p); - virtual bool isPointInGbObject3D(const double& x1, const double& x2, const double& x3, bool& pointIsOnBoundary)=0; - virtual bool isPointInGbObject3D(const double& x1, const double& x2, const double& x3)=0; - - virtual bool isCellInsideGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b); - virtual bool isCellCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b); - virtual bool isCellInsideOrCuttingGbObject3D(const double& x1a,const double& x2a,const double& x3a,const double& x1b,const double& x2b,const double& x3b); - virtual double getCellVolumeInsideGbObject3D(const double& /*x1a*/,const double& /*x2a*/,const double& /*x3a*/,const double& /*x1b*/,const double& /*x2b*/,const double& /*x3b*/){ return -1.0;}; - - virtual bool isInsideCell(const double& minX1,const double& minX2,const double& minX3,const double& maxX1,const double& maxX2,const double& maxX3); - - virtual GbLine3D* createClippedLine3D (GbPoint3D &point1, GbPoint3D &point2) = 0; - virtual std::vector<GbTriangle3D*> getSurfaceTriangleSet()=0; - - virtual void addSurfaceTriangleSet(std::vector<UbTupleFloat3>& /*nodes*/, std::vector<UbTupleInt3>& /*triangles*/) { throw UbException("GbObject3D::addSurfaceTriangleSet - not implemented for "+(std::string)typeid(*this).name()); } - - virtual bool hasRaytracing() { return false; } - virtual bool raytracingSupportsPointsInside() { return false; } - //|r| must be 1! einheitsvector!! - //return negativ value oder zero if no intersection - virtual double getIntersectionRaytraceFactor(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/, const double& /*rx1*/, const double& /*rx2*/, const double& /*rx3*/) { throw UbException("GbObject3D::getIntersectionRaytraceFactor - not implemented"); } + // abstract Methods + virtual void finalize() = 0; // destroys also all dynamic objects (e.g. GbPoints in GbLine) + /** + * Returns the centroid x1 coordinate of this 3D object. + * @return the centroid x1 coordinate of this 3D object + */ + virtual double getX1Centroid() = 0; + /** + * Returns the minimum x1 coordinate of this 3D object. + * @return the minimum x1 coordinate of this 3D object + */ + virtual double getX1Minimum() = 0; + /** + * Returns the maximum x1 coordinate of this 3D object. + * @return the maximum x1 coordinate of this 3D object + */ + virtual double getX1Maximum() = 0; + /** + * Returns the centroid x2 coordinate of this 3D object. + * @return the centroid x2 coordinate of this 3D object + */ + virtual double getX2Centroid() = 0; + /** + * Returns the minimum x2 coordinate of this 3D object. + * @return the minimum x2 coordinate of this 3D object + */ + virtual double getX2Minimum() = 0; + /** + * Returns the maximum x2 coordinate of this 3D object. + * @return the maximum x2 coordinate of this 3D object + */ + virtual double getX2Maximum() = 0; + + virtual double getX3Centroid() = 0; + /** + * Returns the minimum x2 coordinate of this 3D object. + * @return the minimum x2 coordinate of this 3D object + */ + virtual double getX3Minimum() = 0; + /** + * Returns the maximum x2 coordinate of this 3D object. + * @return the maximum x2 coordinate of this 3D object + */ + virtual double getX3Maximum() = 0; + + /*=======================================================*/ + double getLengthX1() { return (getX1Maximum() - getX1Minimum()); } + double getLengthX2() { return (getX2Maximum() - getX2Minimum()); } + double getLengthX3() { return (getX3Maximum() - getX3Minimum()); } + + virtual void setCenterX1Coordinate(const double & /*value*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual void setCenterX2Coordinate(const double & /*value*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual void setCenterX3Coordinate(const double & /*value*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual void setCenterCoordinates(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual void setCenterCoordinates(const UbTupleDouble3 & /*position*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + + // Rotates the Point in relation to the origen. + // Parameters must be radian measure. + virtual void rotate(const double & /*rx1*/, const double & /*rx2*/, const double & /*rx3*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual void translate(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + virtual void scale(const double & /*sx1*/, const double & /*sx2*/, const double & /*sx3*/) + { + throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name()); + } + + virtual bool isPointInGbObject3D(GbPoint3D *p); + virtual bool isPointInGbObject3D(const double &x1, const double &x2, const double &x3, bool &pointIsOnBoundary) = 0; + virtual bool isPointInGbObject3D(const double &x1, const double &x2, const double &x3) = 0; + + virtual bool isCellInsideGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b); + virtual bool isCellCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, const double &x1b, + const double &x2b, const double &x3b); + virtual bool isCellInsideOrCuttingGbObject3D(const double &x1a, const double &x2a, const double &x3a, + const double &x1b, const double &x2b, const double &x3b); + virtual double getCellVolumeInsideGbObject3D(const double & /*x1a*/, const double & /*x2a*/, const double & /*x3a*/, + const double & /*x1b*/, const double & /*x2b*/, const double & /*x3b*/) + { + return -1.0; + }; + + virtual bool isInsideCell(const double &minX1, const double &minX2, const double &minX3, const double &maxX1, + const double &maxX2, const double &maxX3); + + virtual GbLine3D *createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) = 0; + virtual std::vector<GbTriangle3D *> getSurfaceTriangleSet() = 0; + + virtual void addSurfaceTriangleSet(std::vector<UbTupleFloat3> & /*nodes*/, std::vector<UbTupleInt3> & /*triangles*/) + { + throw UbException("GbObject3D::addSurfaceTriangleSet - not implemented for " + + (std::string) typeid(*this).name()); + } + + virtual bool hasRaytracing() { return false; } + virtual bool raytracingSupportsPointsInside() { return false; } + //|r| must be 1! einheitsvector!! + // return negativ value oder zero if no intersection + virtual double getIntersectionRaytraceFactor(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/, + const double & /*rx1*/, const double & /*rx2*/, const double & /*rx3*/) + { + throw UbException("GbObject3D::getIntersectionRaytraceFactor - not implemented"); + } }; /*=========================================================================*/ diff --git a/src/basics/geometry3d/GbPoint3D.cpp b/src/basics/geometry3d/GbPoint3D.cpp index ff6852e78..c7780bb8b 100644 --- a/src/basics/geometry3d/GbPoint3D.cpp +++ b/src/basics/geometry3d/GbPoint3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,116 +35,120 @@ using namespace std; /*=======================================================*/ GbPoint3D::GbPoint3D() -{ - this->x1=0.0; - this->x2=0.0; - this->x3=0.0; -} +{ + this->x1 = 0.0; + this->x2 = 0.0; + this->x3 = 0.0; +} /*=======================================================*/ -GbPoint3D::GbPoint3D(const double& x1, const double& x2, const double& x3) -{ - this->x1=x1; - this->x2=x2; - this->x3=x3; +GbPoint3D::GbPoint3D(const double &x1, const double &x2, const double &x3) +{ + this->x1 = x1; + this->x2 = x2; + this->x3 = x3; } /*=======================================================*/ -GbPoint3D::GbPoint3D(GbPoint3D* point) +GbPoint3D::GbPoint3D(GbPoint3D *point) { - this->x1 = point->x1; - this->x2 = point->x2; - this->x3 = point->x3; -} + this->x1 = point->x1; + this->x2 = point->x2; + this->x3 = point->x3; +} /*=======================================================*/ -double GbPoint3D::getDistance(GbPoint3D* p) +double GbPoint3D::getDistance(GbPoint3D *p) { - double dx1 = this->x1 - p->x1; - double dx2 = this->x2 - p->x2; - double dx3 = this->x3 - p->x3; - return std::sqrt(dx1*dx1 + dx2*dx2 + dx3*dx3); + double dx1 = this->x1 - p->x1; + double dx2 = this->x2 - p->x2; + double dx3 = this->x3 - p->x3; + return std::sqrt(dx1 * dx1 + dx2 * dx2 + dx3 * dx3); } /*=======================================================*/ -bool GbPoint3D::equals(const GbPoint3D* point) const +bool GbPoint3D::equals(const GbPoint3D *point) const { - if(fabs(this->x1-point->x1)>1.E-10) return false; - if(fabs(this->x2-point->x2)>1.E-10) return false; - if(fabs(this->x3-point->x3)>1.E-10) return false; + if (fabs(this->x1 - point->x1) > 1.E-10) + return false; + if (fabs(this->x2 - point->x2) > 1.E-10) + return false; + if (fabs(this->x3 - point->x3) > 1.E-10) + return false; - return true; + return true; } /*=======================================================*/ void GbPoint3D::transform(const double matrix[4][4]) { - double tempX1 = x1; - double tempX2 = x2; - double tempX3 = x3; - x1 = matrix[0][0] * tempX1 + matrix[0][1] * tempX2 + matrix[0][2] * tempX3 + matrix[0][3] * 1.; - x2 = matrix[1][0] * tempX1 + matrix[1][1] * tempX2 + matrix[1][2] * tempX3 + matrix[1][3] * 1.; - x3 = matrix[2][0] * tempX1 + matrix[2][1] * tempX2 + matrix[2][2] * tempX3 + matrix[2][3] * 1.; + double tempX1 = x1; + double tempX2 = x2; + double tempX3 = x3; + x1 = matrix[0][0] * tempX1 + matrix[0][1] * tempX2 + matrix[0][2] * tempX3 + matrix[0][3] * 1.; + x2 = matrix[1][0] * tempX1 + matrix[1][1] * tempX2 + matrix[1][2] * tempX3 + matrix[1][3] * 1.; + x3 = matrix[2][0] * tempX1 + matrix[2][1] * tempX2 + matrix[2][2] * tempX3 + matrix[2][3] * 1.; } /*=======================================================*/ -bool GbPoint3D::isPointInGbObject3D(const double& x1, const double& x2, const double& x3) +bool GbPoint3D::isPointInGbObject3D(const double &x1, const double &x2, const double &x3) { - return (fabs(x1)<1.E-13 && fabs(x2)<1.E-13 && fabs(x3)<1.E-13 ); + return (fabs(x1) < 1.E-13 && fabs(x2) < 1.E-13 && fabs(x3) < 1.E-13); } /*=======================================================*/ -bool GbPoint3D::isPointInGbObject3D(const double& x1, const double& x2, const double& x3, bool& pointIsOnBoundary) +bool GbPoint3D::isPointInGbObject3D(const double &x1, const double &x2, const double &x3, bool &pointIsOnBoundary) { - pointIsOnBoundary = (fabs(x1)<1.E-13 && fabs(x2)<1.E-13 && fabs(x3)<1.E-13 ); - return pointIsOnBoundary; + pointIsOnBoundary = (fabs(x1) < 1.E-13 && fabs(x2) < 1.E-13 && fabs(x3) < 1.E-13); + return pointIsOnBoundary; } /*=======================================================*/ -vector<GbTriangle3D*> GbPoint3D::getSurfaceTriangleSet() -{ - cout<<"GbPoint3D::getSurfaceTriangleSet() - test ... if no exception occurs, everything is fine\n"; - vector<GbTriangle3D*> triangles; - return triangles; //<-empty vector! is okay! - - //old: - //to avoid unnecessary exceptions a point will generate a triangle with - //c3 point with same coordinates - //vector<GbTriangle3D*> triangles; - //GbPoint3D p1(getX1Coordinate(),getX2Coordinate(),getX3Coordinate()); - //triangles.push_back(new GbTriangle3D(new GbPoint3D(p1),new GbPoint3D(p1),new GbPoint3D(p1))); +vector<GbTriangle3D *> GbPoint3D::getSurfaceTriangleSet() +{ + cout << "GbPoint3D::getSurfaceTriangleSet() - test ... if no exception occurs, everything is fine\n"; + vector<GbTriangle3D *> triangles; + return triangles; //<-empty vector! is okay! + + // old: + // to avoid unnecessary exceptions a point will generate a triangle with + // c3 point with same coordinates + // vector<GbTriangle3D*> triangles; + // GbPoint3D p1(getX1Coordinate(),getX2Coordinate(),getX3Coordinate()); + // triangles.push_back(new GbTriangle3D(new GbPoint3D(p1),new GbPoint3D(p1),new GbPoint3D(p1))); } /*=======================================================*/ -GbLine3D* GbPoint3D::createClippedLine3D (GbPoint3D& /*point1*/, GbPoint3D& /*point2*/) +GbLine3D *GbPoint3D::createClippedLine3D(GbPoint3D & /*point1*/, GbPoint3D & /*point2*/) { - throw UbException(UB_EXARGS,"not implemented"); -} + throw UbException(UB_EXARGS, "not implemented"); +} /*=======================================================*/ string GbPoint3D::toString() { - stringstream ss; - ss<<"GbPoint3D["<<this->x1<<","<<this->x2<<","<<this->x3<<"]"; - return((ss.str()).c_str()); + stringstream ss; + ss << "GbPoint3D[" << this->x1 << "," << this->x2 << "," << this->x3 << "]"; + return ((ss.str()).c_str()); } /*=======================================================*/ -void GbPoint3D::translate(const double& dx1, const double& dx2, const double& dx3) -{ - this->x1 += dx1; - this->x2 += dx2; - this->x3 += dx3; - this->notifyObserversObjectChanged(); +void GbPoint3D::translate(const double &dx1, const double &dx2, const double &dx3) +{ + this->x1 += dx1; + this->x2 += dx2; + this->x3 += dx3; + this->notifyObserversObjectChanged(); } /*=======================================================*/ -void GbPoint3D::rotate(const double& rx1, const double& rx2, const double& rx3) -{ - double newX1 = cos(rx3)*cos(rx2)*x1-x2*sin(rx3)*cos(rx1)+x2*cos(rx3)*sin(rx2)*sin(rx1)+x3*sin(rx3)*sin(rx1)+x3*cos(rx3)*sin(rx2)*cos(rx1); - double newX2 = sin(rx3)*cos(rx2)*x1+x2*cos(rx3)*cos(rx1)+x2*sin(rx3)*sin(rx2)*sin(rx1)-x3*cos(rx3)*sin(rx1)+x3*sin(rx3)*sin(rx2)*cos(rx1); - double newX3 = -sin(rx2)*x1+cos(rx2)*sin(rx1)*x2+cos(rx2)*cos(rx1)*x3; +void GbPoint3D::rotate(const double &rx1, const double &rx2, const double &rx3) +{ + double newX1 = cos(rx3) * cos(rx2) * x1 - x2 * sin(rx3) * cos(rx1) + x2 * cos(rx3) * sin(rx2) * sin(rx1) + + x3 * sin(rx3) * sin(rx1) + x3 * cos(rx3) * sin(rx2) * cos(rx1); + double newX2 = sin(rx3) * cos(rx2) * x1 + x2 * cos(rx3) * cos(rx1) + x2 * sin(rx3) * sin(rx2) * sin(rx1) - + x3 * cos(rx3) * sin(rx1) + x3 * sin(rx3) * sin(rx2) * cos(rx1); + double newX3 = -sin(rx2) * x1 + cos(rx2) * sin(rx1) * x2 + cos(rx2) * cos(rx1) * x3; - this->x1 = newX1; - this->x2 = newX2; - this->x3 = newX3; - this->notifyObserversObjectChanged(); + this->x1 = newX1; + this->x2 = newX2; + this->x3 = newX3; + this->notifyObserversObjectChanged(); } /*=======================================================*/ -void GbPoint3D::scale(const double& sx1, const double& sx2, const double& sx3) -{ - this->x1 *= sx1; - this->x2 *= sx2; - this->x3 *= sx3; - this->notifyObserversObjectChanged(); +void GbPoint3D::scale(const double &sx1, const double &sx2, const double &sx3) +{ + this->x1 *= sx1; + this->x2 *= sx2; + this->x3 *= sx3; + this->notifyObserversObjectChanged(); } /*=======================================================*/ - diff --git a/src/basics/geometry3d/GbPoint3D.h b/src/basics/geometry3d/GbPoint3D.h index 68760d789..ccb8a9ab6 100644 --- a/src/basics/geometry3d/GbPoint3D.h +++ b/src/basics/geometry3d/GbPoint3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,9 +33,9 @@ #ifndef GBPOINT3D_H #define GBPOINT3D_H -#include <string> -#include <sstream> #include <cmath> +#include <sstream> +#include <string> #include <GbObject3D.h> @@ -47,63 +47,79 @@ class GbTriangle3D; class GbPoint3D : public GbObject3D { public: - GbPoint3D(); - GbPoint3D(const double& x1, const double& x2, const double& x3); - GbPoint3D(GbPoint3D *point); - ~GbPoint3D() override = default; - - GbPoint3D* clone() override {return new GbPoint3D(this);} - void finalize() override {} - - void setCoordinates(const double& x1, const double& x2, const double& x3) - { - this->x1=x1; - this->x2=x2; - this->x3=x3; - this->notifyObserversObjectChanged(); - } - void setX1(const double& x1) { this->x1=x1; this->notifyObserversObjectChanged(); } - void setX2(const double& x2) { this->x2=x2; this->notifyObserversObjectChanged(); } - void setX3(const double& x3) { this->x3=x3; this->notifyObserversObjectChanged(); } - - double getX1Coordinate() const { return this->x1; } - double getX2Coordinate() const { return this->x2; } - double getX3Coordinate() const { return this->x3; } - - void transform(const double matrix[4][4]); - - double getX1Centroid() override { return this->x1; } - double getX1Minimum() override { return this->x1; } - double getX1Maximum() override { return this->x1; } - double getX2Centroid() override { return this->x2; } - double getX2Minimum() override { return this->x2; } - double getX2Maximum() override { return this->x2; } - double getX3Centroid() override { return this->x3; } - double getX3Minimum() override { return this->x3; } - double getX3Maximum() override { return this->x3; } - - void translate(const double& x1, const double& x2, const double& x3) override; - void rotate(const double& rx1, const double& rx2, const double& rx3) override; - void scale(const double& sx1, const double& sx2, const double& sx3) override; - - double getDistance(GbPoint3D *p); - bool equals(const GbPoint3D* point) const; - bool isPointInGbObject3D(const double& x1, const double& x2, const double& x3, bool& pointIsOnBoundary) override; - bool isPointInGbObject3D(const double& x1, const double& x2, const double& x3) override; - bool isCellInsideGbObject3D(const double& /*x11*/,const double& /*x21*/,const double& /*x31*/,const double& /*x12*/,const double& /*x22*/,const double& /*x23*/) override { return false; } - - std::vector<GbTriangle3D*> getSurfaceTriangleSet() override; - GbLine3D* createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) override; - std::string toString() override; - - using GbObject3D::isPointInGbObject3D; //Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht ausprogrammieren - //, welche sonst hier "ueberdeckt" waere,da es dieselbe methode mit anderen args gibt! - - //member - double x1; - double x2; - double x3; -}; + GbPoint3D(); + GbPoint3D(const double &x1, const double &x2, const double &x3); + GbPoint3D(GbPoint3D *point); + ~GbPoint3D() override = default; + + GbPoint3D *clone() override { return new GbPoint3D(this); } + void finalize() override {} + + void setCoordinates(const double &x1, const double &x2, const double &x3) + { + this->x1 = x1; + this->x2 = x2; + this->x3 = x3; + this->notifyObserversObjectChanged(); + } + void setX1(const double &x1) + { + this->x1 = x1; + this->notifyObserversObjectChanged(); + } + void setX2(const double &x2) + { + this->x2 = x2; + this->notifyObserversObjectChanged(); + } + void setX3(const double &x3) + { + this->x3 = x3; + this->notifyObserversObjectChanged(); + } + double getX1Coordinate() const { return this->x1; } + double getX2Coordinate() const { return this->x2; } + double getX3Coordinate() const { return this->x3; } + + void transform(const double matrix[4][4]); + + double getX1Centroid() override { return this->x1; } + double getX1Minimum() override { return this->x1; } + double getX1Maximum() override { return this->x1; } + double getX2Centroid() override { return this->x2; } + double getX2Minimum() override { return this->x2; } + double getX2Maximum() override { return this->x2; } + double getX3Centroid() override { return this->x3; } + double getX3Minimum() override { return this->x3; } + double getX3Maximum() override { return this->x3; } + + void translate(const double &x1, const double &x2, const double &x3) override; + void rotate(const double &rx1, const double &rx2, const double &rx3) override; + void scale(const double &sx1, const double &sx2, const double &sx3) override; + + double getDistance(GbPoint3D *p); + bool equals(const GbPoint3D *point) const; + bool isPointInGbObject3D(const double &x1, const double &x2, const double &x3, bool &pointIsOnBoundary) override; + bool isPointInGbObject3D(const double &x1, const double &x2, const double &x3) override; + bool isCellInsideGbObject3D(const double & /*x11*/, const double & /*x21*/, const double & /*x31*/, + const double & /*x12*/, const double & /*x22*/, const double & /*x23*/) override + { + return false; + } + + std::vector<GbTriangle3D *> getSurfaceTriangleSet() override; + GbLine3D *createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) override; + std::string toString() override; + + using GbObject3D::isPointInGbObject3D; // Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht + // ausprogrammieren , welche sonst hier "ueberdeckt" waere,da es dieselbe + //methode mit anderen args gibt! + + // member + double x1; + double x2; + double x3; +}; #endif diff --git a/src/basics/geometry3d/GbPolygon3D.cpp b/src/basics/geometry3d/GbPolygon3D.cpp index 713ce56f0..02138f757 100644 --- a/src/basics/geometry3d/GbPolygon3D.cpp +++ b/src/basics/geometry3d/GbPolygon3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,319 +38,332 @@ int GbPolygon3D::counter = 0; GbPolygon3D::GbPolygon3D() { - init(); - counter++; - this->ps = new GbSystem3D::PointSet3(0); + init(); + counter++; + this->ps = new GbSystem3D::PointSet3(0); } void GbPolygon3D::init() { - x1s = 0.0; - x2s = 0.0; - x1min = 0.0; - x1max = 0.0; - x2min = 0.0; - x2max = 0.0; - // points = NULL; - consistent = false; - ps = NULL; + x1s = 0.0; + x2s = 0.0; + x1min = 0.0; + x1max = 0.0; + x2min = 0.0; + x2max = 0.0; + // points = NULL; + consistent = false; + ps = NULL; } /*! -* Creates an empty 3D polygon with the specified capacity. -* @param capacity the initial capacity -*/ + * Creates an empty 3D polygon with the specified capacity. + * @param capacity the initial capacity + */ GbPolygon3D::GbPolygon3D(int capacity) { - init(); - counter++; - this->ps = new GbSystem3D::PointSet3(capacity); - // this.po = new PointObserver(this); + init(); + counter++; + this->ps = new GbSystem3D::PointSet3(capacity); + // this.po = new PointObserver(this); } /** -* Creates a 3D polygon with the specified points. -* @param points the initial points of the polygon -*/ -GbPolygon3D::GbPolygon3D(vector<GbPoint3D>& points) + * Creates a 3D polygon with the specified points. + * @param points the initial points of the polygon + */ +GbPolygon3D::GbPolygon3D(vector<GbPoint3D> &points) { - init(); - counter++; - this->ps = new GbSystem3D::PointSet3((int)points.size()); - this->addPoints(points); + init(); + counter++; + this->ps = new GbSystem3D::PointSet3((int)points.size()); + this->addPoints(points); } /** -* Creates a 3D polygon as clone of the specified 3D polygon. -* @param polygon the 3D polygon to be cloned -*/ -GbPolygon3D::GbPolygon3D(GbPolygon3D* polygon) + * Creates a 3D polygon as clone of the specified 3D polygon. + * @param polygon the 3D polygon to be cloned + */ +GbPolygon3D::GbPolygon3D(GbPolygon3D *polygon) { - this->init(); - counter++; - this->ps = new GbSystem3D::PointSet3((int)polygon->size()); - vector<GbPoint3D> temp = polygon->getPoints(); - this->addPoints( temp ); + this->init(); + counter++; + this->ps = new GbSystem3D::PointSet3((int)polygon->size()); + vector<GbPoint3D> temp = polygon->getPoints(); + this->addPoints(temp); } GbPolygon3D::~GbPolygon3D() { - counter--; - //if(points) - //for(unsigned u=0; u<points->size(); u++) - //{ - // delete (*points)[u]; - //} - // delete this->points; - delete this->ps; + counter--; + // if(points) + // for(unsigned u=0; u<points->size(); u++) + //{ + // delete (*points)[u]; + //} + // delete this->points; + delete this->ps; } /*======================================================================*/ /** -* Returns the number of points. -* @return the number of points -*/ -int GbPolygon3D::size() -{ - return(this->ps->size()); -} + * Returns the number of points. + * @return the number of points + */ +int GbPolygon3D::size() { return (this->ps->size()); } /** -* Returns the number of times this 3D polygon contains the specified point. -* @param point the point -* @return the number of times this 3D polygon contains the specified point -*/ -int GbPolygon3D::contains(GbPoint3D* point) -{ - return(this->ps->contains(point)); -} + * Returns the number of times this 3D polygon contains the specified point. + * @param point the point + * @return the number of times this 3D polygon contains the specified point + */ +int GbPolygon3D::contains(GbPoint3D *point) { return (this->ps->contains(point)); } /** -* Returns the number of times this 3D polygon contains a point equal to the specified point. -* @param point the point -* @return the number of times this 3D polygon contains a point equal to the specified point -*/ -int GbPolygon3D::containsEqual(GbPoint3D* point) -{ - return(this->ps->containsEqual(point)); -} + * Returns the number of times this 3D polygon contains a point equal to the specified point. + * @param point the point + * @return the number of times this 3D polygon contains a point equal to the specified point + */ +int GbPolygon3D::containsEqual(GbPoint3D *point) { return (this->ps->containsEqual(point)); } /** -* Returns true, if this 3D polygon contains the specified line. -* @param point1 the first point -* @param point2 the second point -* @return true, if this 3D polygon contains the specified line -*/ -bool GbPolygon3D::containsLine(GbPoint3D* point1, GbPoint3D* point2) + * Returns true, if this 3D polygon contains the specified line. + * @param point1 the first point + * @param point2 the second point + * @return true, if this 3D polygon contains the specified line + */ +bool GbPolygon3D::containsLine(GbPoint3D *point1, GbPoint3D *point2) { - return(this->ps->containsLine(point1, point2)); + return (this->ps->containsLine(point1, point2)); } /** -* Returns true, if this 3D polygon contains the specified line. -* @param line the line -* @return true, if this 3D polygon contains the specified line -*/ -bool GbPolygon3D::containsLine(GbLine3D* line) + * Returns true, if this 3D polygon contains the specified line. + * @param line the line + * @return true, if this 3D polygon contains the specified line + */ +bool GbPolygon3D::containsLine(GbLine3D *line) { - return(this->ps->containsLine(line->getPoint1(), line->getPoint2())); + return (this->ps->containsLine(line->getPoint1(), line->getPoint2())); } /** -* Returns the first point. -* @return the first point -*/ -GbPoint3D* GbPolygon3D::getFirstPoint() -{ - return(this->ps->getFirstPoint()); -} + * Returns the first point. + * @return the first point + */ +GbPoint3D *GbPolygon3D::getFirstPoint() { return (this->ps->getFirstPoint()); } /** -* Returns the last point. -* @return the last point -*/ -GbPoint3D* GbPolygon3D::getLastPoint() -{ - return(this->ps->getLastPoint()); -} + * Returns the last point. + * @return the last point + */ +GbPoint3D *GbPolygon3D::getLastPoint() { return (this->ps->getLastPoint()); } /** -* Returns the specified point. -* @param index the index -* @return the specified point -* @exception ArrayIndexOutOfBoundsException if the specified index is not valid -*/ -GbPoint3D* GbPolygon3D::getPoint(const int& index) + * Returns the specified point. + * @param index the index + * @return the specified point + * @exception ArrayIndexOutOfBoundsException if the specified index is not valid + */ +GbPoint3D *GbPolygon3D::getPoint(const int &index) { - if(index < 0 || index > this->ps->size()) throw UbException(UB_EXARGS,"ArrayIndexOutOfBoundsException-GbPolygon3D.getPoint()"); - return(this->ps->getPoint(index)); + if (index < 0 || index > this->ps->size()) + throw UbException(UB_EXARGS, "ArrayIndexOutOfBoundsException-GbPolygon3D.getPoint()"); + return (this->ps->getPoint(index)); } /** -* Returns the points. -* @return the points -*/ + * Returns the points. + * @return the points + */ vector<GbPoint3D> GbPolygon3D::getPoints() { - if(!this->consistent) this->calculateValues(); - return(this->points); + if (!this->consistent) + this->calculateValues(); + return (this->points); } /** -* Returns the points within the specified rectangle. -* @param p1 the 1st point of the rectangle -* @param p2 the 2nd point of the rectangle -* @return the points within the specified rectangle -*/ -vector<GbPoint3D> GbPolygon3D::getPoints(GbPoint3D* p1, GbPoint3D* p2) + * Returns the points within the specified rectangle. + * @param p1 the 1st point of the rectangle + * @param p2 the 2nd point of the rectangle + * @return the points within the specified rectangle + */ +vector<GbPoint3D> GbPolygon3D::getPoints(GbPoint3D *p1, GbPoint3D *p2) { - return(this->getPoints(p1->x1, p1->x2, p1->x3, p2->x1, p2->x2, p2->x3)); + return (this->getPoints(p1->x1, p1->x2, p1->x3, p2->x1, p2->x2, p2->x3)); } /** -* Returns the points within the specified rectangle. -* @param p1x1 the 1st x1 coordinate of the rectangle -* @param p1x2 the 1st x2 coordinate of the rectangle -* @param p1x3 the 1st x3 coordinate of the rectangle -* @param p2x1 the 2nd x1 coordinate of the rectangle -* @param p2x2 the 2nd x2 coordinate of the rectangle -* @param p2x3 the 2nd x3 coordinate of the rectangle -* @return the points within the specified rectangle -*/ -vector<GbPoint3D> GbPolygon3D::getPoints(const double& p1x1, const double& p1x2, const double& p1x3, const double& p2x1, const double& p2x2, const double& p2x3) + * Returns the points within the specified rectangle. + * @param p1x1 the 1st x1 coordinate of the rectangle + * @param p1x2 the 1st x2 coordinate of the rectangle + * @param p1x3 the 1st x3 coordinate of the rectangle + * @param p2x1 the 2nd x1 coordinate of the rectangle + * @param p2x2 the 2nd x2 coordinate of the rectangle + * @param p2x3 the 2nd x3 coordinate of the rectangle + * @return the points within the specified rectangle + */ +vector<GbPoint3D> GbPolygon3D::getPoints(const double &p1x1, const double &p1x2, const double &p1x3, const double &p2x1, + const double &p2x2, const double &p2x3) { - double x1min, x1max, x2min, x2max, x3min, x3max; + double x1min, x1max, x2min, x2max, x3min, x3max; - if(UbMath::less(p1x1, p2x1)) { x1min = p1x1; x1max = p2x1; } - else { x1min = p2x1; x1max = p1x1; } - if(UbMath::less(p1x2, p2x2)) { x2min = p1x2; x2max = p2x2; } - else { x2min = p2x2; x2max = p1x2; } - if(UbMath::less(p1x3, p2x3)) { x3min = p1x3; x3max = p2x3; } - else { x3min = p2x3; x3max = p1x3; } + if (UbMath::less(p1x1, p2x1)) { + x1min = p1x1; + x1max = p2x1; + } else { + x1min = p2x1; + x1max = p1x1; + } + if (UbMath::less(p1x2, p2x2)) { + x2min = p1x2; + x2max = p2x2; + } else { + x2min = p2x2; + x2max = p1x2; + } + if (UbMath::less(p1x3, p2x3)) { + x3min = p1x3; + x3max = p2x3; + } else { + x3min = p2x3; + x3max = p1x3; + } - GbSystem3D::PointSet3 *pts = new GbSystem3D::PointSet3(1); + GbSystem3D::PointSet3 *pts = new GbSystem3D::PointSet3(1); - if(!this->consistent) this->calculateValues(); - for(int i=this->size()-1; i>=0; i--) - { - if(UbMath::lessEqual(x1min, (this->points)[i].x1) && UbMath::greaterEqual(x1max, (this->points)[i].x1) && - UbMath::lessEqual(x2min, (this->points)[i].x2) && UbMath::greaterEqual(x2max, (this->points)[i].x2) && - UbMath::lessEqual(x3min, (this->points)[i].x3) && UbMath::greaterEqual(x3max, (this->points)[i].x3)) pts->add((this->points)[i]); - } - return(pts->getPoints()); + if (!this->consistent) + this->calculateValues(); + for (int i = this->size() - 1; i >= 0; i--) { + if (UbMath::lessEqual(x1min, (this->points)[i].x1) && UbMath::greaterEqual(x1max, (this->points)[i].x1) && + UbMath::lessEqual(x2min, (this->points)[i].x2) && UbMath::greaterEqual(x2max, (this->points)[i].x2) && + UbMath::lessEqual(x3min, (this->points)[i].x3) && UbMath::greaterEqual(x3max, (this->points)[i].x3)) + pts->add((this->points)[i]); + } + return (pts->getPoints()); } /** -* Returns the area of this polygon. -* The area is positive for positive ordered points, otherwise negative. -* @return the area of this polygon -*/ -//double getArea() + * Returns the area of this polygon. + * The area is positive for positive ordered points, otherwise negative. + * @return the area of this polygon + */ +// double getArea() //{ // if(!this.consistent) this.calculateValues(); // return(this.area); //} double GbPolygon3D::getX1Centroid() { - if(!this->consistent) this->calculateValues(); - return(this->x1s); + if (!this->consistent) + this->calculateValues(); + return (this->x1s); } double GbPolygon3D::getX1Minimum() { - if(!this->consistent) this->calculateValues(); - return(this->x1min); + if (!this->consistent) + this->calculateValues(); + return (this->x1min); } double GbPolygon3D::getX1Maximum() { - if(!this->consistent) this->calculateValues(); - return(this->x1max); + if (!this->consistent) + this->calculateValues(); + return (this->x1max); } double GbPolygon3D::getX2Centroid() { - if(!this->consistent) this->calculateValues(); - return(this->x2s); + if (!this->consistent) + this->calculateValues(); + return (this->x2s); } double GbPolygon3D::getX2Minimum() { - if(!this->consistent) this->calculateValues(); - return(this->x2min); + if (!this->consistent) + this->calculateValues(); + return (this->x2min); } double GbPolygon3D::getX2Maximum() { - if(!this->consistent) this->calculateValues(); - return(this->x2max); + if (!this->consistent) + this->calculateValues(); + return (this->x2max); } double GbPolygon3D::getX3Centroid() { - if(!this->consistent) this->calculateValues(); - return(this->x3s); + if (!this->consistent) + this->calculateValues(); + return (this->x3s); } double GbPolygon3D::getX3Minimum() { - if(!this->consistent) this->calculateValues(); - return(this->x3min); + if (!this->consistent) + this->calculateValues(); + return (this->x3min); } double GbPolygon3D::getX3Maximum() { - if(!this->consistent) this->calculateValues(); - return(this->x3max); + if (!this->consistent) + this->calculateValues(); + return (this->x3max); } /** -* Adds a point to the end of this polygon. Notifies the observers of this 3D polygon. -* @param point the point -*/ -void GbPolygon3D::addPoint(GbPoint3D* point) + * Adds a point to the end of this polygon. Notifies the observers of this 3D polygon. + * @param point the point + */ +void GbPolygon3D::addPoint(GbPoint3D *point) { - //if((this instanceof GbPolygon3D) && !(point instanceof GbPoint3D)) throw new IllegalArgumentException("GbPolygon3D.addPoint(): points of 3D polygons have to be 3D points!"); + // if((this instanceof GbPolygon3D) && !(point instanceof GbPoint3D)) throw new + // IllegalArgumentException("GbPolygon3D.addPoint(): points of 3D polygons have to be 3D points!"); - this->ps->add(point); - //point.addObserver(this.po); - this->consistent = false; - //super.notifyObservers(); + this->ps->add(point); + // point.addObserver(this.po); + this->consistent = false; + // super.notifyObservers(); } /** -* Adds a number of points to the end of this polygon. Notifies the observers of this 3D polygon. -* @param points the points -*/ -void GbPolygon3D::addPoints(vector<GbPoint3D>& points) + * Adds a number of points to the end of this polygon. Notifies the observers of this 3D polygon. + * @param points the points + */ +void GbPolygon3D::addPoints(vector<GbPoint3D> &points) { - //if((this instanceof GbPolygon3D) && (points.getClass().getComponentType() != GbPoint3D.class)) throw new IllegalArgumentException("GbPolygon3D.addPoints(): points of 3D polygons have to be 3D points!"); + // if((this instanceof GbPolygon3D) && (points.getClass().getComponentType() != GbPoint3D.class)) throw new + // IllegalArgumentException("GbPolygon3D.addPoints(): points of 3D polygons have to be 3D points!"); - this->ps->add(points); - //for(int i=0; i<points.length; i++) points[i].addObserver(this.po); - this->consistent = false; - //super.notifyObservers(); + this->ps->add(points); + // for(int i=0; i<points.length; i++) points[i].addObserver(this.po); + this->consistent = false; + // super.notifyObservers(); } /** -* Removes all points from this polygon. Notifies the observers of this 3D polygon. -*/ + * Removes all points from this polygon. Notifies the observers of this 3D polygon. + */ void GbPolygon3D::clear() { - // delete this->points; - this->ps->clearAndTrim(); - delete this->ps; + // delete this->points; + this->ps->clearAndTrim(); + delete this->ps; - //for(int i=points.length-1; i>=0; i--) points[i].removeObserver(this.po); - this->consistent = false; - //super.notifyObservers(); + // for(int i=points.length-1; i>=0; i--) points[i].removeObserver(this.po); + this->consistent = false; + // super.notifyObservers(); } /** -* Returns a string representation of this 3D polygon. -* @return a string representation of this 3D polygon -*/ + * Returns a string representation of this 3D polygon. + * @return a string representation of this 3D polygon + */ string GbPolygon3D::toString() { - stringstream ss; - ss<<"GbPolygon3D["; - ss<<this->size()<<" points"; - ss<<"]"<<endl; - for(int u=0; u<this->size(); u++) - ss<<this->ps->getPoint(u)->toString()<<endl; + stringstream ss; + ss << "GbPolygon3D["; + ss << this->size() << " points"; + ss << "]" << endl; + for (int u = 0; u < this->size(); u++) + ss << this->ps->getPoint(u)->toString() << endl; - return(ss.str()); + return (ss.str()); } /*======================================================================*/ void GbPolygon3D::calculateValues() { - this->x1s = 0.0; - this->x2s = 0.0; - this->x3s = 0.0; - this->x1min = 0.0; - this->x1max = 0.0; - this->x2min = 0.0; - this->x2max = 0.0; - this->x3min = 0.0; - this->x3max = 0.0; - throw UbException(UB_EXARGS,"should be implemented"); + this->x1s = 0.0; + this->x2s = 0.0; + this->x3s = 0.0; + this->x1min = 0.0; + this->x1max = 0.0; + this->x2min = 0.0; + this->x2max = 0.0; + this->x3min = 0.0; + this->x3max = 0.0; + throw UbException(UB_EXARGS, "should be implemented"); } /*======================================================================*/ - - diff --git a/src/basics/geometry3d/GbPolygon3D.h b/src/basics/geometry3d/GbPolygon3D.h index 279b8bdb8..e4f44b5be 100644 --- a/src/basics/geometry3d/GbPolygon3D.h +++ b/src/basics/geometry3d/GbPolygon3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,254 +33,248 @@ #ifndef GBPOLYGON3D_H #define GBPOLYGON3D_H -#include <sstream> #include <iostream> +#include <sstream> - -#include <GbObject3D.h> #include <GbLine3D.h> -#include <GbTriangle3D.h> +#include <GbObject3D.h> #include <GbSystem3D.h> +#include <GbTriangle3D.h> #include <PointerDefinitions.h> - /*=========================================================================*/ -//! \class GbPolygon2D +//! \class GbPolygon2D /* */ //! \brief This Class provides basic 3D polygon objects. class GbPolygon3D : public GbObject3D { public: - using GbObject3D::isPointInGbObject3D; //Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht ausprogrammieren, welche sonst hier "ueberdeckt" waere + using GbObject3D::isPointInGbObject3D; // Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht + // ausprogrammieren, welche sonst hier "ueberdeckt" waere private: - /*======================================================================*/ - double x1s ; - double x2s ; - double x3s ; - double x1min; - double x1max; - double x2min; - double x2max; - double x3min; - double x3max; - - std::vector<GbPoint3D> points; - bool consistent; + /*======================================================================*/ + double x1s; + double x2s; + double x3s; + double x1min; + double x1max; + double x2min; + double x2max; + double x3min; + double x3max; - GbSystem3D::PointSet3 *ps; - //private PointObserver po = null; + std::vector<GbPoint3D> points; + bool consistent; - void init(); + GbSystem3D::PointSet3 *ps; + // private PointObserver po = null; - /*======================================================================*/ + void init(); + /*======================================================================*/ - /*======================================================================*/ - /* Construcrors */ - /* */ - /* - * Creates an empty 2D polygon. - */ + /*======================================================================*/ + /* Construcrors */ + /* */ + /* + * Creates an empty 2D polygon. + */ public: - static int counter; - GbPolygon3D(); - /* - * Creates an empty 2D polygon with the specified capacity. - * @param capacity the initial capacity - */ - GbPolygon3D(int capacity); - /* - * Creates a 2D polygon with the specified points. - * @param points the initial points of the polygon - */ - GbPolygon3D(std::vector<GbPoint3D> &points); - /* - * Creates a 2D polygon as clone of the specified 2D polygon. - * @param polygon the 2D polygon to be cloned - */ - GbPolygon3D(GbPolygon3D *polygon); - - ~GbPolygon3D() override; + static int counter; + GbPolygon3D(); + /* + * Creates an empty 2D polygon with the specified capacity. + * @param capacity the initial capacity + */ + GbPolygon3D(int capacity); + /* + * Creates a 2D polygon with the specified points. + * @param points the initial points of the polygon + */ + GbPolygon3D(std::vector<GbPoint3D> &points); + /* + * Creates a 2D polygon as clone of the specified 2D polygon. + * @param polygon the 2D polygon to be cloned + */ + GbPolygon3D(GbPolygon3D *polygon); - /*======================================================================*/ + ~GbPolygon3D() override; + /*======================================================================*/ - /*======================================================================*/ - /* Methoden */ - /* */ - /* - * Creates a 2D polygon as clone of this 2D polygon. - */ - GbPolygon3D* clone() override { return(new GbPolygon3D(this)); } - void finalize() override - { - throw UbException(UB_EXARGS,"toDo"); - } + /*======================================================================*/ + /* Methoden */ + /* */ + /* + * Creates a 2D polygon as clone of this 2D polygon. + */ + GbPolygon3D *clone() override { return (new GbPolygon3D(this)); } + void finalize() override { throw UbException(UB_EXARGS, "toDo"); } - /* - * Returns the number of points. - * @return the number of points - */ - int size(); - /* - * Returns the number of times this 2D polygon contains the specified point. - * @param point the point - * @return the number of times this 2D polygon contains the specified point - */ - int contains(GbPoint3D *point); - /* - * Returns the number of times this 2D polygon contains a point equal to the specified point. - * @param point the point - * @return the number of times this 2D polygon contains a point equal to the specified point - */ - int containsEqual(GbPoint3D* point); - /* - * Returns true, if this 2D polygon contains the specified line. - * @param point1 the first point - * @param point2 the second point - * @return true, if this 2D polygon contains the specified line - */ - bool containsLine(GbPoint3D* point1, GbPoint3D* point2); - /* - * Returns true, if this 2D polygon contains the specified line. - * @param line the line - * @return true, if this 2D polygon contains the specified line - */ - bool containsLine(GbLine3D* line); - /* - * Returns the first point. - * @return the first point - */ - GbPoint3D* getFirstPoint(); - /* - * Returns the last point. - * @return the last point - */ - GbPoint3D* getLastPoint(); - /* - * Returns the specified point. - * @param index the index - * @return the specified point - * @exception ArrayIndexOutOfBoundsException if the specified index is not valid - */ - GbPoint3D* getPoint(const int& index); - /* - * Returns the points. - * @return the points - */ - std::vector<GbPoint3D> getPoints(); - /* - * Returns the points within the specified rectangle. - * @param p1 the 1st point of the rectangle - * @param p2 the 2nd point of the rectangle - * @return the points within the specified rectangle - */ - std::vector<GbPoint3D> getPoints(GbPoint3D* p1, GbPoint3D* p2); - /* - * Returns the points within the specified rectangle. - * @param p1x1 the 1st x1 coordinate of the rectangle - * @param p1x2 the 1st x2 coordinate of the rectangle - * @param p2x1 the 2nd x1 coordinate of the rectangle - * @param p2x2 the 2nd x2 coordinate of the rectangle - * @return the points within the specified rectangle - */ - std::vector<GbPoint3D> getPoints(const double& p1x1, const double& p1x2, const double& p1x3, const double& p2x1, const double& p2x2, const double& p2x3); - /* - * Returns the area of this polygon. - * The area is positive for positive ordered points, otherwise negative. - * @return the area of this polygon - */ - //double getArea() - //{ - // if(!this.consistent) this.calculateValues(); - // return(this.area); - //} - double getX1Centroid() override; - double getX1Minimum() override; - double getX1Maximum() override; - double getX2Centroid() override; - double getX2Minimum() override; - double getX2Maximum() override; - double getX3Centroid() override; - double getX3Minimum() override; - double getX3Maximum() override; + /* + * Returns the number of points. + * @return the number of points + */ + int size(); + /* + * Returns the number of times this 2D polygon contains the specified point. + * @param point the point + * @return the number of times this 2D polygon contains the specified point + */ + int contains(GbPoint3D *point); + /* + * Returns the number of times this 2D polygon contains a point equal to the specified point. + * @param point the point + * @return the number of times this 2D polygon contains a point equal to the specified point + */ + int containsEqual(GbPoint3D *point); + /* + * Returns true, if this 2D polygon contains the specified line. + * @param point1 the first point + * @param point2 the second point + * @return true, if this 2D polygon contains the specified line + */ + bool containsLine(GbPoint3D *point1, GbPoint3D *point2); + /* + * Returns true, if this 2D polygon contains the specified line. + * @param line the line + * @return true, if this 2D polygon contains the specified line + */ + bool containsLine(GbLine3D *line); + /* + * Returns the first point. + * @return the first point + */ + GbPoint3D *getFirstPoint(); + /* + * Returns the last point. + * @return the last point + */ + GbPoint3D *getLastPoint(); + /* + * Returns the specified point. + * @param index the index + * @return the specified point + * @exception ArrayIndexOutOfBoundsException if the specified index is not valid + */ + GbPoint3D *getPoint(const int &index); + /* + * Returns the points. + * @return the points + */ + std::vector<GbPoint3D> getPoints(); + /* + * Returns the points within the specified rectangle. + * @param p1 the 1st point of the rectangle + * @param p2 the 2nd point of the rectangle + * @return the points within the specified rectangle + */ + std::vector<GbPoint3D> getPoints(GbPoint3D *p1, GbPoint3D *p2); + /* + * Returns the points within the specified rectangle. + * @param p1x1 the 1st x1 coordinate of the rectangle + * @param p1x2 the 1st x2 coordinate of the rectangle + * @param p2x1 the 2nd x1 coordinate of the rectangle + * @param p2x2 the 2nd x2 coordinate of the rectangle + * @return the points within the specified rectangle + */ + std::vector<GbPoint3D> getPoints(const double &p1x1, const double &p1x2, const double &p1x3, const double &p2x1, + const double &p2x2, const double &p2x3); + /* + * Returns the area of this polygon. + * The area is positive for positive ordered points, otherwise negative. + * @return the area of this polygon + */ + // double getArea() + //{ + // if(!this.consistent) this.calculateValues(); + // return(this.area); + //} + double getX1Centroid() override; + double getX1Minimum() override; + double getX1Maximum() override; + double getX2Centroid() override; + double getX2Minimum() override; + double getX2Maximum() override; + double getX3Centroid() override; + double getX3Minimum() override; + double getX3Maximum() override; - /* - * Adds a point to the end of this polygon. Notifies the observers of this 2D polygon. - * @param point the point - */ - void addPoint(GbPoint3D* point); - /* - * Adds a number of points to the end of this polygon. Notifies the observers of this 2D polygon. - * @param points the points - */ - void addPoints(std::vector<GbPoint3D>& points); - /* - * Removes all points from this polygon. Notifies the observers of this 2D polygon. - */ - void clear(); + /* + * Adds a point to the end of this polygon. Notifies the observers of this 2D polygon. + * @param point the point + */ + void addPoint(GbPoint3D *point); + /* + * Adds a number of points to the end of this polygon. Notifies the observers of this 2D polygon. + * @param points the points + */ + void addPoints(std::vector<GbPoint3D> &points); + /* + * Removes all points from this polygon. Notifies the observers of this 2D polygon. + */ + void clear(); - /* - * Returns true if this 2D polygon equals the specified object. - * Two polygon are equal, if their points are equal. - * <BR>Note that the order of points is recognized! - * @return true if this 2D polygon equals the specified object - * @see GbPoint2D#equals(java.lang.Object) - * @see GbPoint3D#equals(java.lang.Object) - */ - // bool equals(Object object) - // { - // try - // { - // GbPolygon2D polygon = (GbPolygon2D) object; - //int n = this.size(); + /* + * Returns true if this 2D polygon equals the specified object. + * Two polygon are equal, if their points are equal. + * <BR>Note that the order of points is recognized! + * @return true if this 2D polygon equals the specified object + * @see GbPoint2D#equals(java.lang.Object) + * @see GbPoint3D#equals(java.lang.Object) + */ + // bool equals(Object object) + // { + // try + // { + // GbPolygon2D polygon = (GbPolygon2D) object; + // int n = this.size(); - //if(n != polygon.size()) return(false); - //for(int i=0; i<n; i++) if(!this.getPoint(i).equals(polygon.getPoint(i))) return(false); - //return(true); - // } - // catch(Exception e){ return(false); } - // } - std::vector<GbTriangle3D*> getSurfaceTriangleSet() override - { - std::cout<<"GbPolygon3D::getSurfaceTriangleSet() - not implemented\n"; - std::vector<GbTriangle3D*> tmp; - return tmp; - } - bool isPointInGbObject3D(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/) override - { - throw UbException(__FILE__, __LINE__, "GbPolygon3D::isPointInObject3D- not implemented"); - } - bool isPointInGbObject3D(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/, bool& /*pointIsOnBoundary*/) override - { - throw UbException(__FILE__, __LINE__, "GbPolygon3D::isPointInObject3D- not implemented"); - } - bool isCellInsideGbObject3D(const double& /*x1a*/,const double& /*x2a*/,const double& /*x3a*/,const double& /*x1b*/,const double& /*x2b*/,const double& /*x3b*/) override { return false; } + // if(n != polygon.size()) return(false); + // for(int i=0; i<n; i++) if(!this.getPoint(i).equals(polygon.getPoint(i))) return(false); + // return(true); + // } + // catch(Exception e){ return(false); } + // } + std::vector<GbTriangle3D *> getSurfaceTriangleSet() override + { + std::cout << "GbPolygon3D::getSurfaceTriangleSet() - not implemented\n"; + std::vector<GbTriangle3D *> tmp; + return tmp; + } + bool isPointInGbObject3D(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/) override + { + throw UbException(__FILE__, __LINE__, "GbPolygon3D::isPointInObject3D- not implemented"); + } + bool isPointInGbObject3D(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/, + bool & /*pointIsOnBoundary*/) override + { + throw UbException(__FILE__, __LINE__, "GbPolygon3D::isPointInObject3D- not implemented"); + } + bool isCellInsideGbObject3D(const double & /*x1a*/, const double & /*x2a*/, const double & /*x3a*/, + const double & /*x1b*/, const double & /*x2b*/, const double & /*x3b*/) override + { + return false; + } - GbLine3D* createClippedLine3D (GbPoint3D& /*point1*/, GbPoint3D & /*point2*/) override - { - throw UbException(__FILE__, __LINE__, "GbPolygon3D::createClippedLine3D - not implemented"); - } + GbLine3D *createClippedLine3D(GbPoint3D & /*point1*/, GbPoint3D & /*point2*/) override + { + throw UbException(__FILE__, __LINE__, "GbPolygon3D::createClippedLine3D - not implemented"); + } -/* - * Returns a string representation of this 2D polygon. - * @return a string representation of this 2D polygon - */ - std::string toString() override; + /* + * Returns a string representation of this 2D polygon. + * @return a string representation of this 2D polygon + */ + std::string toString() override; - /*======================================================================*/ - /* Private Methoden */ - /* */ - void calculateValues(); - /*======================================================================*/ + /*======================================================================*/ + /* Private Methoden */ + /* */ + void calculateValues(); + /*======================================================================*/ }; /*=========================================================================*/ #endif - - - - - - diff --git a/src/basics/geometry3d/GbSystem3D.cpp b/src/basics/geometry3d/GbSystem3D.cpp index 142b584f3..2a49aff7d 100644 --- a/src/basics/geometry3d/GbSystem3D.cpp +++ b/src/basics/geometry3d/GbSystem3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,143 +30,161 @@ //! \ingroup geometry3d //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#include <GbSystem3D.h> -#include <GbPolygon3D.h> #include <GbCuboid3D.h> +#include <GbPolygon3D.h> +#include <GbSystem3D.h> using namespace std; -double GbSystem3D::getDistance(const GbPoint3D& p11, const GbPoint3D& p12) +double GbSystem3D::getDistance(const GbPoint3D &p11, const GbPoint3D &p12) { - double dx1 = p11.x1 - p12.x1; - double dx2 = p11.x2 - p12.x2; - double dx3 = p11.x3 - p12.x3; - return std::sqrt(dx1*dx1+dx2*dx2+dx3*dx3); + double dx1 = p11.x1 - p12.x1; + double dx2 = p11.x2 - p12.x2; + double dx3 = p11.x3 - p12.x3; + return std::sqrt(dx1 * dx1 + dx2 * dx2 + dx3 * dx3); } -GbPoint3D* GbSystem3D::calculateIntersectionPoint3D(GbPoint3D& p11, GbPoint3D& p12, GbPoint3D& p21, GbPoint3D& p22) +GbPoint3D *GbSystem3D::calculateIntersectionPoint3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22) { - if(UbMath::less2(p11.x1, p12.x1, p21.x1, p22.x1)) return NULL; - if(UbMath::less2(p11.x2, p12.x2, p21.x2, p22.x2)) return NULL; - if(UbMath::less2(p11.x3, p12.x3, p21.x3, p22.x3)) return NULL; - if(UbMath::greater2(p11.x1, p12.x1, p21.x1, p22.x1)) return NULL; - if(UbMath::greater2(p11.x2, p12.x2, p21.x2, p22.x2)) return NULL; - if(UbMath::greater2(p11.x3, p12.x3, p21.x3, p22.x3)) return NULL; - - double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED......... - double a12 = p12.x2 - p11.x2; // - double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1 - double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2 - double a22 = p21.x2 - p22.x2; // - double a23 = p21.x3 - p22.x3; //.................................. - double b1 = p21.x1 - p11.x1; - double b2 = p21.x2 - p11.x2; - double b3 = p21.x3 - p11.x3; - double d1 = a11*a22 - a12*a21; - double d2 = a11*a23 - a13*a21; - double d3 = a12*a23 - a13*a22; - double t; - - if(UbMath::zero(d1) && UbMath::zero(d2) && UbMath::zero(d3)) return NULL; - if(UbMath::zero(d1)) - { - if(!UbMath::zero(d2)) t = (a23*b1-a21*b3)/d2; - else t = (a23*b2-a22*b3)/d3; - } - else if(UbMath::zero(d2)) - { - if(!UbMath::zero(d1)) t = (a22*b1-a21*b2)/d1; - else t = (a23*b2-a22*b3)/d3; - } - else if(UbMath::zero(d3)) - { - if(!UbMath::zero(d1)) t = (a22*b1-a21*b2)/d1; - else t = (a23*b1-a21*b3)/d2; - } - else return NULL; - - double x1 = p11.x1 + t*a11; - double x2 = p11.x2 + t*a12; - double x3 = p11.x3 + t*a13; - - if(UbMath::inClosedInterval(x1, p11.x1, p12.x1) && UbMath::inClosedInterval(x1, p21.x1, p22.x1) && - UbMath::inClosedInterval(x2, p11.x2, p12.x2) && UbMath::inClosedInterval(x2, p21.x2, p22.x2) && - UbMath::inClosedInterval(x3, p11.x3, p12.x3) && UbMath::inClosedInterval(x3, p21.x3, p22.x3) ) return new GbPoint3D(x1, x2, x3); - - return NULL; + if (UbMath::less2(p11.x1, p12.x1, p21.x1, p22.x1)) + return NULL; + if (UbMath::less2(p11.x2, p12.x2, p21.x2, p22.x2)) + return NULL; + if (UbMath::less2(p11.x3, p12.x3, p21.x3, p22.x3)) + return NULL; + if (UbMath::greater2(p11.x1, p12.x1, p21.x1, p22.x1)) + return NULL; + if (UbMath::greater2(p11.x2, p12.x2, p21.x2, p22.x2)) + return NULL; + if (UbMath::greater2(p11.x3, p12.x3, p21.x3, p22.x3)) + return NULL; + + double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED......... + double a12 = p12.x2 - p11.x2; // + double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1 + double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2 + double a22 = p21.x2 - p22.x2; // + double a23 = p21.x3 - p22.x3; //.................................. + double b1 = p21.x1 - p11.x1; + double b2 = p21.x2 - p11.x2; + double b3 = p21.x3 - p11.x3; + double d1 = a11 * a22 - a12 * a21; + double d2 = a11 * a23 - a13 * a21; + double d3 = a12 * a23 - a13 * a22; + double t; + + if (UbMath::zero(d1) && UbMath::zero(d2) && UbMath::zero(d3)) + return NULL; + if (UbMath::zero(d1)) { + if (!UbMath::zero(d2)) + t = (a23 * b1 - a21 * b3) / d2; + else + t = (a23 * b2 - a22 * b3) / d3; + } else if (UbMath::zero(d2)) { + if (!UbMath::zero(d1)) + t = (a22 * b1 - a21 * b2) / d1; + else + t = (a23 * b2 - a22 * b3) / d3; + } else if (UbMath::zero(d3)) { + if (!UbMath::zero(d1)) + t = (a22 * b1 - a21 * b2) / d1; + else + t = (a23 * b1 - a21 * b3) / d2; + } else + return NULL; + + double x1 = p11.x1 + t * a11; + double x2 = p11.x2 + t * a12; + double x3 = p11.x3 + t * a13; + + if (UbMath::inClosedInterval(x1, p11.x1, p12.x1) && UbMath::inClosedInterval(x1, p21.x1, p22.x1) && + UbMath::inClosedInterval(x2, p11.x2, p12.x2) && UbMath::inClosedInterval(x2, p21.x2, p22.x2) && + UbMath::inClosedInterval(x3, p11.x3, p12.x3) && UbMath::inClosedInterval(x3, p21.x3, p22.x3)) + return new GbPoint3D(x1, x2, x3); + + return NULL; } /*=================================================================*/ -//Line1: p11 -> p12 and Line2: p21 -> p22 -bool GbSystem3D::hasIntersectionPoint3D(GbPoint3D& p11, GbPoint3D& p12, GbPoint3D& p21, GbPoint3D& p22) +// Line1: p11 -> p12 and Line2: p21 -> p22 +bool GbSystem3D::hasIntersectionPoint3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22) { - if(UbMath::less2(p11.x1, p12.x1, p21.x1, p22.x1)) return false; - if(UbMath::less2(p11.x2, p12.x2, p21.x2, p22.x2)) return false; - if(UbMath::less2(p11.x3, p12.x3, p21.x3, p22.x3)) return false; - if(UbMath::greater2(p11.x1, p12.x1, p21.x1, p22.x1)) return false; - if(UbMath::greater2(p11.x2, p12.x2, p21.x2, p22.x2)) return false; - if(UbMath::greater2(p11.x3, p12.x3, p21.x3, p22.x3)) return false; - - double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED......... - double a12 = p12.x2 - p11.x2; // - double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1 - double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2 - double a22 = p21.x2 - p22.x2; // - double a23 = p21.x3 - p22.x3; //.................................. - double b1 = p21.x1 - p11.x1; - double b2 = p21.x2 - p11.x2; - double b3 = p21.x3 - p11.x3; - double d1 = a11*a22 - a12*a21; - double d2 = a11*a23 - a13*a21; - double d3 = a12*a23 - a13*a22; - double t; - - if(UbMath::zero(d1) && UbMath::zero(d2) && UbMath::zero(d3)) return false; - if(UbMath::zero(d1)) - { - if(!UbMath::zero(d2)) t = (a23*b1-a21*b3)/d2; - else t = (a23*b2-a22*b3)/d3; - } - else if(UbMath::zero(d2)) - { - if(!UbMath::zero(d1)) t = (a22*b1-a21*b2)/d1; - else t = (a23*b2-a22*b3)/d3; - } - else if(UbMath::zero(d3)) - { - if(!UbMath::zero(d1)) t = (a22*b1-a21*b2)/d1; - else t = (a23*b1-a21*b3)/d2; - } - else return false; - - double x1 = p11.x1 + t*a11; - double x2 = p11.x2 + t*a12; - double x3 = p11.x3 + t*a13; - - if(UbMath::inClosedInterval(x1, p11.x1, p12.x1) && UbMath::inClosedInterval(x1, p21.x1, p22.x1) && - UbMath::inClosedInterval(x2, p11.x2, p12.x2) && UbMath::inClosedInterval(x2, p21.x2, p22.x2) && - UbMath::inClosedInterval(x3, p11.x3, p12.x3) && UbMath::inClosedInterval(x3, p21.x3, p22.x3)) return true; - return false; + if (UbMath::less2(p11.x1, p12.x1, p21.x1, p22.x1)) + return false; + if (UbMath::less2(p11.x2, p12.x2, p21.x2, p22.x2)) + return false; + if (UbMath::less2(p11.x3, p12.x3, p21.x3, p22.x3)) + return false; + if (UbMath::greater2(p11.x1, p12.x1, p21.x1, p22.x1)) + return false; + if (UbMath::greater2(p11.x2, p12.x2, p21.x2, p22.x2)) + return false; + if (UbMath::greater2(p11.x3, p12.x3, p21.x3, p22.x3)) + return false; + + double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED......... + double a12 = p12.x2 - p11.x2; // + double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1 + double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2 + double a22 = p21.x2 - p22.x2; // + double a23 = p21.x3 - p22.x3; //.................................. + double b1 = p21.x1 - p11.x1; + double b2 = p21.x2 - p11.x2; + double b3 = p21.x3 - p11.x3; + double d1 = a11 * a22 - a12 * a21; + double d2 = a11 * a23 - a13 * a21; + double d3 = a12 * a23 - a13 * a22; + double t; + + if (UbMath::zero(d1) && UbMath::zero(d2) && UbMath::zero(d3)) + return false; + if (UbMath::zero(d1)) { + if (!UbMath::zero(d2)) + t = (a23 * b1 - a21 * b3) / d2; + else + t = (a23 * b2 - a22 * b3) / d3; + } else if (UbMath::zero(d2)) { + if (!UbMath::zero(d1)) + t = (a22 * b1 - a21 * b2) / d1; + else + t = (a23 * b2 - a22 * b3) / d3; + } else if (UbMath::zero(d3)) { + if (!UbMath::zero(d1)) + t = (a22 * b1 - a21 * b2) / d1; + else + t = (a23 * b1 - a21 * b3) / d2; + } else + return false; + + double x1 = p11.x1 + t * a11; + double x2 = p11.x2 + t * a12; + double x3 = p11.x3 + t * a13; + + if (UbMath::inClosedInterval(x1, p11.x1, p12.x1) && UbMath::inClosedInterval(x1, p21.x1, p22.x1) && + UbMath::inClosedInterval(x2, p11.x2, p12.x2) && UbMath::inClosedInterval(x2, p21.x2, p22.x2) && + UbMath::inClosedInterval(x3, p11.x3, p12.x3) && UbMath::inClosedInterval(x3, p21.x3, p22.x3)) + return true; + return false; } - /*======================================================================*/ +/*======================================================================*/ // // // /*======================================================================*/ // /* Private Methoden (Parallelism) */ // /* */ -bool GbSystem3D::isParallelIn3D(GbPoint3D& p11, GbPoint3D& p12, GbPoint3D& p21, GbPoint3D& p22) +bool GbSystem3D::isParallelIn3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22) { - double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED......... - double a12 = p12.x2 - p11.x2; // - double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1 - double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2 - double a22 = p21.x2 - p22.x2; // - double a23 = p21.x3 - p22.x3; //.................................. - - return (UbMath::zero(a11*a22 - a12*a21) && UbMath::zero(a11*a23 - a13*a21) && UbMath::zero(a12*a23 - a13*a22)); + double a11 = p12.x1 - p11.x1; //..HOW PARAMETERS ARE USED......... + double a12 = p12.x2 - p11.x2; // + double a13 = p12.x3 - p11.x3; // p11 and p12 represent line 1 + double a21 = p21.x1 - p22.x1; // p21 and p22 represent line 2 + double a22 = p21.x2 - p22.x2; // + double a23 = p21.x3 - p22.x3; //.................................. + + return (UbMath::zero(a11 * a22 - a12 * a21) && UbMath::zero(a11 * a23 - a13 * a21) && + UbMath::zero(a12 * a23 - a13 * a22)); } /*======================================================================*/ - /*======================================================================*/ /* General Clipping Methods */ //......................................................................*/ @@ -181,134 +199,152 @@ bool GbSystem3D::isParallelIn3D(GbPoint3D& p11, GbPoint3D& p12, GbPoint3D& p21, /*======================================================================*/ /* Private Methoden (Clipping Lines) */ /* */ -GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, double x2a, double x3a, double x1b, double x2b, double x3b) +GbLine3D *GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, double x2a, double x3a, double x1b, + double x2b, double x3b) { - GbPoint3D *p1 = new GbPoint3D(pA); - GbPoint3D *p2 = new GbPoint3D(pB); - - if(UbMath::greater(x1a, x1b)) { double x1 = x1a; x1a = x1b; x1b = x1; } - if(UbMath::greater(x2a, x2b)) { double x2 = x2a; x2a = x2b; x2b = x2; } - if(UbMath::greater(x3a, x3b)) { double x3 = x3a; x3a = x3b; x3b = x3; } - - double f; - - /*-------------------------------------------------------------------*/ - /* Schneiden an vorderer Kante */ - /* */ - if(UbMath::less(p1->x3, x3a)) - { - if(UbMath::less(p2->x3, x3a)) { delete p1; delete p2; return NULL; } - - f = (x3a-p1->x3)/(p1->x3-p2->x3); - p1->x1 += (p1->x1-p2->x1)*f; - p1->x2 += (p1->x2-p2->x2)*f; - p1->x3 = x3a; - } - else if(UbMath::less(p2->x3, x3a)) - { - f = (x3a-p2->x3)/(p2->x3-p1->x3); - p2->x1 += (p2->x1-p1->x1)*f; - p2->x2 += (p2->x2-p1->x2)*f; - p2->x3 = x3a; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an unterer Kante */ - /* */ - if(UbMath::less(p1->x2, x2a)) - { - if(UbMath::less(p2->x2, x2a)) { delete p1; delete p2; return NULL; - } - - f = (x2a-p1->x2)/(p1->x2-p2->x2); - p1->x1 += (p1->x1-p2->x1)*f; - p1->x3 += (p1->x3-p2->x3)*f; - p1->x2 = x2a; - } - else if(UbMath::less(p2->x2, x2a)) - { - f = (x2a-p2->x2)/(p2->x2-p1->x2); - p2->x1 += (p2->x1-p1->x1)*f; - p2->x3 += (p2->x3-p1->x3)*f; - p2->x2 = x2a; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an rechter Kante */ - /* */ - if(UbMath::greater(p1->x1, x1b)) - { - if(UbMath::greater(p2->x1, x1b)) { delete p1;delete p2; return NULL;} - - f = (x1b-p1->x1)/(p1->x1-p2->x1); - p1->x2 += (p1->x2-p2->x2)*f; - p1->x3 += (p1->x3-p2->x3)*f; - p1->x1 = x1b; - } - else if(UbMath::greater(p2->x1, x1b)) - { - f = (x1b-p2->x1)/(p2->x1-p1->x1); - p2->x2 += (p2->x2-p1->x2)*f; - p2->x3 += (p2->x3-p1->x3)*f; - p2->x1 = x1b; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an hinterer Kante */ - /* */ - if(UbMath::greater(p1->x3, x3b)) - { - if(UbMath::greater(p2->x3, x3b)) { delete p1;delete p2; return NULL;} - - f = (x3b-p1->x3)/(p1->x3-p2->x3); - p1->x1 += (p1->x1-p2->x1)*f; - p1->x2 += (p1->x2-p2->x2)*f; - p1->x3 = x3b; - } - else if(UbMath::greater(p2->x3, x3b)) - { - f = (x3b-p2->x3)/(p2->x3-p1->x3); - p2->x1 += (p2->x1-p1->x1)*f; - p2->x2 += (p2->x2-p1->x2)*f; - p2->x3 = x3b; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an oberer Kante */ - /* */ - if(UbMath::greater(p1->x2, x2b)) - { - if(UbMath::greater(p2->x2, x2b)) { delete p1;delete p2; return NULL;} - - f = (x2b-p1->x2)/(p1->x2-p2->x2); - p1->x1 += (p1->x1-p2->x1)*f; - p1->x3 += (p1->x3-p2->x3)*f; - p1->x2 = x2b; - } - else if(UbMath::greater(p2->x2, x2b)) - { - f = (x2b-p2->x2)/(p2->x2-p1->x2); - p2->x1 += (p2->x1-p1->x1)*f; - p2->x3 += (p2->x3-p1->x3)*f; - p2->x2 = x2b; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an linker Kante */ - /* */ - if(UbMath::less(p1->x1, x1a)) - { - if(UbMath::less(p2->x1, x1a)) { delete p1;delete p2; return NULL;} - - f = (x1a-p1->x1)/(p1->x1-p2->x1); - p1->x2 += (p1->x2-p2->x2)*f; - p1->x3 += (p1->x3-p2->x3)*f; - p1->x1 = x1a; - } - else if(UbMath::less(p2->x1, x1a)) - { - f = (x1a-p2->x1)/(p2->x1-p1->x1); - p2->x2 += (p2->x2-p1->x2)*f; - p2->x3 += (p2->x3-p1->x3)*f; - p2->x1 = x1a; - } - /*-------------------------------------------------------------------*/ - return new GbLine3D(p1, p2); + GbPoint3D *p1 = new GbPoint3D(pA); + GbPoint3D *p2 = new GbPoint3D(pB); + + if (UbMath::greater(x1a, x1b)) { + double x1 = x1a; + x1a = x1b; + x1b = x1; + } + if (UbMath::greater(x2a, x2b)) { + double x2 = x2a; + x2a = x2b; + x2b = x2; + } + if (UbMath::greater(x3a, x3b)) { + double x3 = x3a; + x3a = x3b; + x3b = x3; + } + + double f; + + /*-------------------------------------------------------------------*/ + /* Schneiden an vorderer Kante */ + /* */ + if (UbMath::less(p1->x3, x3a)) { + if (UbMath::less(p2->x3, x3a)) { + delete p1; + delete p2; + return NULL; + } + + f = (x3a - p1->x3) / (p1->x3 - p2->x3); + p1->x1 += (p1->x1 - p2->x1) * f; + p1->x2 += (p1->x2 - p2->x2) * f; + p1->x3 = x3a; + } else if (UbMath::less(p2->x3, x3a)) { + f = (x3a - p2->x3) / (p2->x3 - p1->x3); + p2->x1 += (p2->x1 - p1->x1) * f; + p2->x2 += (p2->x2 - p1->x2) * f; + p2->x3 = x3a; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an unterer Kante */ + /* */ + if (UbMath::less(p1->x2, x2a)) { + if (UbMath::less(p2->x2, x2a)) { + delete p1; + delete p2; + return NULL; + } + + f = (x2a - p1->x2) / (p1->x2 - p2->x2); + p1->x1 += (p1->x1 - p2->x1) * f; + p1->x3 += (p1->x3 - p2->x3) * f; + p1->x2 = x2a; + } else if (UbMath::less(p2->x2, x2a)) { + f = (x2a - p2->x2) / (p2->x2 - p1->x2); + p2->x1 += (p2->x1 - p1->x1) * f; + p2->x3 += (p2->x3 - p1->x3) * f; + p2->x2 = x2a; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an rechter Kante */ + /* */ + if (UbMath::greater(p1->x1, x1b)) { + if (UbMath::greater(p2->x1, x1b)) { + delete p1; + delete p2; + return NULL; + } + + f = (x1b - p1->x1) / (p1->x1 - p2->x1); + p1->x2 += (p1->x2 - p2->x2) * f; + p1->x3 += (p1->x3 - p2->x3) * f; + p1->x1 = x1b; + } else if (UbMath::greater(p2->x1, x1b)) { + f = (x1b - p2->x1) / (p2->x1 - p1->x1); + p2->x2 += (p2->x2 - p1->x2) * f; + p2->x3 += (p2->x3 - p1->x3) * f; + p2->x1 = x1b; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an hinterer Kante */ + /* */ + if (UbMath::greater(p1->x3, x3b)) { + if (UbMath::greater(p2->x3, x3b)) { + delete p1; + delete p2; + return NULL; + } + + f = (x3b - p1->x3) / (p1->x3 - p2->x3); + p1->x1 += (p1->x1 - p2->x1) * f; + p1->x2 += (p1->x2 - p2->x2) * f; + p1->x3 = x3b; + } else if (UbMath::greater(p2->x3, x3b)) { + f = (x3b - p2->x3) / (p2->x3 - p1->x3); + p2->x1 += (p2->x1 - p1->x1) * f; + p2->x2 += (p2->x2 - p1->x2) * f; + p2->x3 = x3b; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an oberer Kante */ + /* */ + if (UbMath::greater(p1->x2, x2b)) { + if (UbMath::greater(p2->x2, x2b)) { + delete p1; + delete p2; + return NULL; + } + + f = (x2b - p1->x2) / (p1->x2 - p2->x2); + p1->x1 += (p1->x1 - p2->x1) * f; + p1->x3 += (p1->x3 - p2->x3) * f; + p1->x2 = x2b; + } else if (UbMath::greater(p2->x2, x2b)) { + f = (x2b - p2->x2) / (p2->x2 - p1->x2); + p2->x1 += (p2->x1 - p1->x1) * f; + p2->x3 += (p2->x3 - p1->x3) * f; + p2->x2 = x2b; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an linker Kante */ + /* */ + if (UbMath::less(p1->x1, x1a)) { + if (UbMath::less(p2->x1, x1a)) { + delete p1; + delete p2; + return NULL; + } + + f = (x1a - p1->x1) / (p1->x1 - p2->x1); + p1->x2 += (p1->x2 - p2->x2) * f; + p1->x3 += (p1->x3 - p2->x3) * f; + p1->x1 = x1a; + } else if (UbMath::less(p2->x1, x1a)) { + f = (x1a - p2->x1) / (p2->x1 - p1->x1); + p2->x2 += (p2->x2 - p1->x2) * f; + p2->x3 += (p2->x3 - p1->x3) * f; + p2->x1 = x1a; + } + /*-------------------------------------------------------------------*/ + return new GbLine3D(p1, p2); } // /*======================================================================*/ // /* Private Methoden (Clipping Rectangles) */ @@ -346,7 +382,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(flag) // { // f = (x12-(*points)[i]->x2)/((*points)[i]->x2-last->x2); -// ps.add(new GbPoint3D((*points)[i]->x1 + ((*points)[i]->x1-last->x1)*f, x12, (*points)[i]->x3 + ((*points)[i]->x3-last->x3)*f)); +// ps.add(new GbPoint3D((*points)[i]->x1 + ((*points)[i]->x1-last->x1)*f, x12, (*points)[i]->x3 + +//((*points)[i]->x3-last->x3)*f)); // } // flag = false; // } @@ -355,7 +392,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(!flag) // { // f = (x12-(*points)[i]->x2)/((*points)[i]->x2-last->x2); -// ps.add(new GbPoint3D((*points)[i]->x1 + ((*points)[i]->x1-last->x1)*f, x12, (*points)[i]->x3 + ((*points)[i]->x3-last->x3)*f)); +// ps.add(new GbPoint3D((*points)[i]->x1 + ((*points)[i]->x1-last->x1)*f, x12, (*points)[i]->x3 + +//((*points)[i]->x3-last->x3)*f)); // } // ps.add((*points)[i]); // flag = true; @@ -393,7 +431,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(flag) // { // f = (x21-(*points)[i]->x1)/((*points)[i]->x1-last->x1); -// ps.add(new GbPoint3D(x21, (*points)[i]->x2 + ((*points)[i]->x2-last->x2)*f, (*points)[i]->x3 + ((*points)[i]->x3-last->x3)*f)); +// ps.add(new GbPoint3D(x21, (*points)[i]->x2 + ((*points)[i]->x2-last->x2)*f, (*points)[i]->x3 + +//((*points)[i]->x3-last->x3)*f)); // } // flag = false; // } @@ -402,7 +441,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(!flag) // { // f = (x21-(*points)[i]->x1)/((*points)[i]->x1-last->x1); -// ps.add(new GbPoint3D(x21, (*points)[i]->x2 + ((*points)[i]->x2-last->x2)*f, (*points)[i]->x3 + ((*points)[i]->x3-last->x3)*f)); +// ps.add(new GbPoint3D(x21, (*points)[i]->x2 + ((*points)[i]->x2-last->x2)*f, (*points)[i]->x3 + +//((*points)[i]->x3-last->x3)*f)); // } // ps.add(points[i]); // flag = true; @@ -440,7 +480,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(flag) // { // f = (x22-(*points)[i]->x2)/(points[i].x2-last.x2); -// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, x22, points[i].x3 + (points[i].x3-last.x3)*f)); +// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, x22, points[i].x3 + +//(points[i].x3-last.x3)*f)); // } // flag = false; // } @@ -449,7 +490,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(!flag) // { // f = (x22-points[i].x2)/(points[i].x2-last.x2); -// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, x22, points[i].x3 + (points[i].x3-last.x3)*f)); +// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, x22, points[i].x3 + +//(points[i].x3-last.x3)*f)); // } // ps.add(points[i]); // flag = true; @@ -487,7 +529,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(flag) // { // f = (x11-points[i].x1)/(points[i].x1-last.x1); -// ps.add(new GbPoint3D(x11, points[i].x2 + (points[i].x2-last.x2)*f, points[i].x3 + (points[i].x3-last.x3)*f)); +// ps.add(new GbPoint3D(x11, points[i].x2 + (points[i].x2-last.x2)*f, points[i].x3 + +//(points[i].x3-last.x3)*f)); // } // flag = false; // } @@ -496,7 +539,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(!flag) // { // f = (x11-points[i].x1)/(points[i].x1-last.x1); -// ps.add(new GbPoint3D(x11, points[i].x2 + (points[i].x2-last.x2)*f, points[i].x3 + (points[i].x3-last.x3)*f)); +// ps.add(new GbPoint3D(x11, points[i].x2 + (points[i].x2-last.x2)*f, points[i].x3 + +//(points[i].x3-last.x3)*f)); // } // ps.add(points[i]); // flag = true; @@ -557,7 +601,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(flag) // { // f = (x13-points[i].x3)/(points[i].x3-last.x3); -// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f, x13)); +// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f, +//x13)); // } // flag = false; // } @@ -566,7 +611,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(!flag) // { // f = (x13-points[i].x3)/(points[i].x3-last.x3); -// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f, x13)); +// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f, +//x13)); // } // ps.add(points[i]); // flag = true; @@ -604,7 +650,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(flag) // { // f = (x23-points[i].x3)/(points[i].x3-last.x3); -// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f, x23)); +// ps.add(new GbPoint3D(points[i].x1 + (points[i].x1-last.x1)*f, points[i].x2 + (points[i].x2-last.x2)*f, +//x23)); // } // flag = false; // } @@ -613,7 +660,8 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // if(!flag) // { // f = (x23-points[i].x3)/(points[i].x3-last.x3); -// ps.add(new GbPoint3D(points[i].x1 + ((*points)[i]->x1-last.x1)*f, (*points)[i]->x2 + ((*points)[i]->x2-last.x2)*f, x23)); +// ps.add(new GbPoint3D(points[i].x1 + ((*points)[i]->x1-last.x1)*f, (*points)[i]->x2 + +//((*points)[i]->x2-last.x2)*f, x23)); // } // ps.add(points[i]); // flag = true; @@ -636,404 +684,420 @@ GbLine3D* GbSystem3D::createClipLine3D(GbPoint3D &pA, GbPoint3D &pB, double x1a, // // return(polygon); // } -GbPolygon3D* GbSystem3D::clipPolygon3D(vector<GbPoint3D> points, double x11, double x12, double x13, double x21, double x22, double x23) +GbPolygon3D *GbSystem3D::clipPolygon3D(vector<GbPoint3D> points, double x11, double x12, double x13, double x21, + double x22, double x23) { - GbPoint3D last; - PointSet3 ps(points); - bool flag = false; - int n = (int)points.size(); - int i; - double f; - - if(n == 0) return NULL; - if(UbMath::greater(x11, x21)) { double ax = x11; x11 = x21; x21 = ax; } - if(UbMath::greater(x12, x22)) { double ay = x12; x12 = x22; x22 = ay; } - if(UbMath::greater(x13, x23)) { double az = x13; x13 = x23; x23 = az; } - - /*-------------------------------------------------------------------*/ - /* Schneiden an vorderer Kante */ - /* */ - if(UbMath::less(ps.getX3Minimum(), x13)) - { - ps.clear(); - last = (points)[0]; - if(UbMath::less((points)[0].x3, x13)) flag = false; - else - { - ps.add((points)[0]); - flag = true; - } - for(i=1; i<n; i++) - { - if(UbMath::less((points)[i].x3, x13)) - { - if(flag) - { - f = (x13-(points)[i].x3)/((points)[i].x3-last.x3); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, (points)[i].x2 + ((points)[i].x2-last.x2)*f, x13)); - } - flag = false; - } - else - { - if(!flag) - { - f = (x13-(points)[i].x3)/((points)[i].x3-last.x3); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, (points)[i].x2 + ((points)[i].x2-last.x2)*f, x13)); - } - ps.add((points)[i]); - flag = true; - } - last = (points)[i]; - } - if(!((UbMath::less((points)[0].x3, x13)) ^ flag)) - { - f = (x13-(points)[0].x3)/((points)[0].x3-last.x3); - ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1-last.x1)*f, (points)[0].x2 + ((points)[0].x2-last.x2)*f, x13)); - } - - points = ps.getPoints(); - n = (int)points.size(); - - if(n == 0) return NULL; - } - - /*-------------------------------------------------------------------*/ - /* Schneiden an unterer Kante */ - /* */ - if(UbMath::less(ps.getX2Minimum(), x12)) - { - ps.clear(); - last = (points)[0]; - if(UbMath::less((points)[0].x2, x12)) flag = false; - else - { - ps.add((points)[0]); - flag = true; - } - for(i=1; i<n; i++) - { - if(UbMath::less((points)[i].x2, x12)) - { - if(flag) - { - f = (x12-(points)[i].x2)/((points)[i].x2-last.x2); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, x12, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - } - flag = false; - } - else - { - if(!flag) - { - f = (x12-(points)[i].x2)/((points)[i].x2-last.x2); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, x12, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - } - ps.add((points)[i]); - flag = true; - } - last = (points)[i]; - } - if(!((UbMath::less((points)[0].x2, x12)) ^ flag)) - { - f = (x12-(points)[0].x2)/((points)[0].x2-last.x2); - ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1-last.x1)*f, x12, (points)[0].x3 + ((points)[0].x3-last.x3)*f)); - } - - points = ps.getPoints(); - n = (int)points.size(); - - if(n == 0) return NULL; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an rechter Kante */ - /* */ - - if(UbMath::greater(ps.getX1Maximum(), x21)) - { - ps.clear(); - last = (points)[0]; - if(UbMath::greater((points)[0].x1, x21)) flag = false; - else - { - ps.add((points)[0]); - flag = true; - } - for(i=1; i<n; i++) - { - if(UbMath::greater((points)[i].x1, x21)) - { - if(flag) - { - f = (x21-(points)[i].x1)/((points)[i].x1-last.x1); - ps.add(GbPoint3D(x21, (points)[i].x2 + ((points)[i].x2-last.x2)*f, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - } - flag = false; - } - else - { - if(!flag) - { - f = (x21-(points)[i].x1)/((points)[i].x1-last.x1); - ps.add(GbPoint3D(x21, (points)[i].x2 + ((points)[i].x2-last.x2)*f, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - } - ps.add((points)[i]); - flag = true; - } - last = (points)[i]; - } - if(!((UbMath::greater((points)[0].x1, x21)) ^ flag)) - { - f = (x21-(points)[0].x1)/((points)[0].x1-last.x1); - ps.add(GbPoint3D(x21, (points)[0].x2 + ((points)[0].x2-last.x2)*f, (points)[0].x3 + ((points)[0].x3-last.x3)*f)); - } - - points = ps.getPoints(); - n = (int)points.size(); - - if(n == 0) return NULL; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an hinterer Kante */ - /* */ - if(UbMath::greater(ps.getX3Maximum(), x23)) - { - ps.clear(); - last = (points)[0]; - if(UbMath::greater((points)[0].x3, x23)) flag = false; - else - { - ps.add((points)[0]); - flag = true; - } - for(i=1; i<n; i++) - { - if(UbMath::greater((points)[i].x3, x23)) - { - if(flag) - { - f = (x23-(points)[i].x3)/((points)[i].x3-last.x3); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, (points)[i].x2 + ((points)[i].x2-last.x2)*f, x23)); - } - flag = false; - } - else - { - if(!flag) - { - f = (x23-(points)[i].x3)/((points)[i].x3-last.x3); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, (points)[i].x2 + ((points)[i].x2-last.x2)*f, x23)); - } - ps.add((points)[i]); - flag = true; - } - last = (points)[i]; - } - if(!((UbMath::greater((points)[0].x3, x23)) ^ flag)) - { - f = (x23-(points)[0].x3)/((points)[0].x3-last.x3); - ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1-last.x1)*f, (points)[0].x2 + ((points)[0].x2-last.x2)*f, x23)); - } - - points = ps.getPoints(); - n = (int)points.size(); - - if(n == 0) return NULL; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an oberer Kante */ - /* */ - - if(UbMath::greater(ps.getX2Maximum(), x22)) - { - ps.clear(); - last = (points)[0]; - if(UbMath::greater((points)[0].x2, x22)) flag = false; - else - { - ps.add((points)[0]); - flag = true; - } - for(i=1; i<n; i++) - { - if(UbMath::greater((points)[i].x2, x22)) - { - if(flag) - { - f = (x22-(points)[i].x2)/((points)[i].x2-last.x2); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, x22, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - } - flag = false; - } - else - { - if(!flag) - { - f = (x22-(points)[i].x2)/((points)[i].x2-last.x2); - ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1-last.x1)*f, x22, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - } - ps.add((points)[i]); - flag = true; - } - last = (points)[i]; - } - if(!((UbMath::greater((points)[0].x2, x22)) ^ flag)) - { - f = (x22-(points)[0].x2)/((points)[0].x2-last.x2); - ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1-last.x1)*f, x22, (points)[0].x3 + ((points)[0].x3-last.x3)*f)); - } - - points = ps.getPoints(); - n = (int)points.size(); - - if(n == 0) return NULL; - } - /*-------------------------------------------------------------------*/ - /* Schneiden an linker Kante */ - /* */ - if(UbMath::less(ps.getX1Minimum(), x11)) - { - ps.clear(); - last = (points)[0]; - if(UbMath::less((points)[0].x1, x11)) flag = false; - else - { - ps.add((points)[0]); - flag = true; - } - for(i=1; i<n; i++) - { - if(UbMath::less((points)[i].x1, x11)) - { - if(flag) - { - f = (x11-(points)[i].x1)/((points)[i].x1-last.x1); - ps.add(GbPoint3D(x11, (points)[i].x2 + ((points)[i].x2-last.x2)*f, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - - } - flag = false; - } - else - { - if(!flag) - { - f = (x11-(points)[i].x1)/((points)[i].x1-last.x1); - ps.add(GbPoint3D(x11, (points)[i].x2 + ((points)[i].x2-last.x2)*f, (points)[i].x3 + ((points)[i].x3-last.x3)*f)); - } - ps.add((points)[i]); - flag = true; - } - last = (points)[i]; - } - if(!((UbMath::less((points)[0].x1, x11)) ^ flag)) - { - f = (x11-(points)[0].x1)/((points)[0].x1-last.x1); - ps.add(GbPoint3D(x11, (points)[0].x2 + ((points)[0].x2-last.x2)*f, (points)[0].x3 + ((points)[0].x3-last.x3)*f)); - } - - points = ps.getPoints(); - n = (int)points.size(); - - if(n == 0) return NULL; - } - /*-------------------------------------------------------------------*/ - return new GbPolygon3D(points); + GbPoint3D last; + PointSet3 ps(points); + bool flag = false; + int n = (int)points.size(); + int i; + double f; + + if (n == 0) + return NULL; + if (UbMath::greater(x11, x21)) { + double ax = x11; + x11 = x21; + x21 = ax; + } + if (UbMath::greater(x12, x22)) { + double ay = x12; + x12 = x22; + x22 = ay; + } + if (UbMath::greater(x13, x23)) { + double az = x13; + x13 = x23; + x23 = az; + } + + /*-------------------------------------------------------------------*/ + /* Schneiden an vorderer Kante */ + /* */ + if (UbMath::less(ps.getX3Minimum(), x13)) { + ps.clear(); + last = (points)[0]; + if (UbMath::less((points)[0].x3, x13)) + flag = false; + else { + ps.add((points)[0]); + flag = true; + } + for (i = 1; i < n; i++) { + if (UbMath::less((points)[i].x3, x13)) { + if (flag) { + f = (x13 - (points)[i].x3) / ((points)[i].x3 - last.x3); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, + (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x13)); + } + flag = false; + } else { + if (!flag) { + f = (x13 - (points)[i].x3) / ((points)[i].x3 - last.x3); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, + (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x13)); + } + ps.add((points)[i]); + flag = true; + } + last = (points)[i]; + } + if (!((UbMath::less((points)[0].x3, x13)) ^ flag)) { + f = (x13 - (points)[0].x3) / ((points)[0].x3 - last.x3); + ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f, + (points)[0].x2 + ((points)[0].x2 - last.x2) * f, x13)); + } + + points = ps.getPoints(); + n = (int)points.size(); + + if (n == 0) + return NULL; + } + + /*-------------------------------------------------------------------*/ + /* Schneiden an unterer Kante */ + /* */ + if (UbMath::less(ps.getX2Minimum(), x12)) { + ps.clear(); + last = (points)[0]; + if (UbMath::less((points)[0].x2, x12)) + flag = false; + else { + ps.add((points)[0]); + flag = true; + } + for (i = 1; i < n; i++) { + if (UbMath::less((points)[i].x2, x12)) { + if (flag) { + f = (x12 - (points)[i].x2) / ((points)[i].x2 - last.x2); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x12, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + flag = false; + } else { + if (!flag) { + f = (x12 - (points)[i].x2) / ((points)[i].x2 - last.x2); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x12, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + ps.add((points)[i]); + flag = true; + } + last = (points)[i]; + } + if (!((UbMath::less((points)[0].x2, x12)) ^ flag)) { + f = (x12 - (points)[0].x2) / ((points)[0].x2 - last.x2); + ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f, x12, + (points)[0].x3 + ((points)[0].x3 - last.x3) * f)); + } + + points = ps.getPoints(); + n = (int)points.size(); + + if (n == 0) + return NULL; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an rechter Kante */ + /* */ + + if (UbMath::greater(ps.getX1Maximum(), x21)) { + ps.clear(); + last = (points)[0]; + if (UbMath::greater((points)[0].x1, x21)) + flag = false; + else { + ps.add((points)[0]); + flag = true; + } + for (i = 1; i < n; i++) { + if (UbMath::greater((points)[i].x1, x21)) { + if (flag) { + f = (x21 - (points)[i].x1) / ((points)[i].x1 - last.x1); + ps.add(GbPoint3D(x21, (points)[i].x2 + ((points)[i].x2 - last.x2) * f, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + flag = false; + } else { + if (!flag) { + f = (x21 - (points)[i].x1) / ((points)[i].x1 - last.x1); + ps.add(GbPoint3D(x21, (points)[i].x2 + ((points)[i].x2 - last.x2) * f, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + ps.add((points)[i]); + flag = true; + } + last = (points)[i]; + } + if (!((UbMath::greater((points)[0].x1, x21)) ^ flag)) { + f = (x21 - (points)[0].x1) / ((points)[0].x1 - last.x1); + ps.add(GbPoint3D(x21, (points)[0].x2 + ((points)[0].x2 - last.x2) * f, + (points)[0].x3 + ((points)[0].x3 - last.x3) * f)); + } + + points = ps.getPoints(); + n = (int)points.size(); + + if (n == 0) + return NULL; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an hinterer Kante */ + /* */ + if (UbMath::greater(ps.getX3Maximum(), x23)) { + ps.clear(); + last = (points)[0]; + if (UbMath::greater((points)[0].x3, x23)) + flag = false; + else { + ps.add((points)[0]); + flag = true; + } + for (i = 1; i < n; i++) { + if (UbMath::greater((points)[i].x3, x23)) { + if (flag) { + f = (x23 - (points)[i].x3) / ((points)[i].x3 - last.x3); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, + (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x23)); + } + flag = false; + } else { + if (!flag) { + f = (x23 - (points)[i].x3) / ((points)[i].x3 - last.x3); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, + (points)[i].x2 + ((points)[i].x2 - last.x2) * f, x23)); + } + ps.add((points)[i]); + flag = true; + } + last = (points)[i]; + } + if (!((UbMath::greater((points)[0].x3, x23)) ^ flag)) { + f = (x23 - (points)[0].x3) / ((points)[0].x3 - last.x3); + ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f, + (points)[0].x2 + ((points)[0].x2 - last.x2) * f, x23)); + } + + points = ps.getPoints(); + n = (int)points.size(); + + if (n == 0) + return NULL; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an oberer Kante */ + /* */ + + if (UbMath::greater(ps.getX2Maximum(), x22)) { + ps.clear(); + last = (points)[0]; + if (UbMath::greater((points)[0].x2, x22)) + flag = false; + else { + ps.add((points)[0]); + flag = true; + } + for (i = 1; i < n; i++) { + if (UbMath::greater((points)[i].x2, x22)) { + if (flag) { + f = (x22 - (points)[i].x2) / ((points)[i].x2 - last.x2); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x22, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + flag = false; + } else { + if (!flag) { + f = (x22 - (points)[i].x2) / ((points)[i].x2 - last.x2); + ps.add(GbPoint3D((points)[i].x1 + ((points)[i].x1 - last.x1) * f, x22, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + ps.add((points)[i]); + flag = true; + } + last = (points)[i]; + } + if (!((UbMath::greater((points)[0].x2, x22)) ^ flag)) { + f = (x22 - (points)[0].x2) / ((points)[0].x2 - last.x2); + ps.add(GbPoint3D((points)[0].x1 + ((points)[0].x1 - last.x1) * f, x22, + (points)[0].x3 + ((points)[0].x3 - last.x3) * f)); + } + + points = ps.getPoints(); + n = (int)points.size(); + + if (n == 0) + return NULL; + } + /*-------------------------------------------------------------------*/ + /* Schneiden an linker Kante */ + /* */ + if (UbMath::less(ps.getX1Minimum(), x11)) { + ps.clear(); + last = (points)[0]; + if (UbMath::less((points)[0].x1, x11)) + flag = false; + else { + ps.add((points)[0]); + flag = true; + } + for (i = 1; i < n; i++) { + if (UbMath::less((points)[i].x1, x11)) { + if (flag) { + f = (x11 - (points)[i].x1) / ((points)[i].x1 - last.x1); + ps.add(GbPoint3D(x11, (points)[i].x2 + ((points)[i].x2 - last.x2) * f, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + flag = false; + } else { + if (!flag) { + f = (x11 - (points)[i].x1) / ((points)[i].x1 - last.x1); + ps.add(GbPoint3D(x11, (points)[i].x2 + ((points)[i].x2 - last.x2) * f, + (points)[i].x3 + ((points)[i].x3 - last.x3) * f)); + } + ps.add((points)[i]); + flag = true; + } + last = (points)[i]; + } + if (!((UbMath::less((points)[0].x1, x11)) ^ flag)) { + f = (x11 - (points)[0].x1) / ((points)[0].x1 - last.x1); + ps.add(GbPoint3D(x11, (points)[0].x2 + ((points)[0].x2 - last.x2) * f, + (points)[0].x3 + ((points)[0].x3 - last.x3) * f)); + } + + points = ps.getPoints(); + n = (int)points.size(); + + if (n == 0) + return NULL; + } + /*-------------------------------------------------------------------*/ + return new GbPolygon3D(points); } /*=========================================================================*/ -GbCuboid3D* GbSystem3D::clipRectangle3D(GbPoint3D& p1, GbPoint3D& p2, double x11, double x12, double x13, double x21, double x22, double x23) +GbCuboid3D *GbSystem3D::clipRectangle3D(GbPoint3D &p1, GbPoint3D &p2, double x11, double x12, double x13, double x21, + double x22, double x23) { - double r11 = p1.x1; - double r12 = p1.x2; - double r13 = p1.x3; - double r21 = p2.x1; - double r22 = p2.x2; - double r23 = p2.x3; - - if(UbMath::greater(x11, x21)) { double ax = x11; x11 = x21; x21 = ax; } - if(UbMath::greater(x12, x22)) { double ay = x12; x12 = x22; x22 = ay; } - if(UbMath::greater(x13, x23)) { double az = x13; x13 = x23; x23 = az; } - if(UbMath::greater(r11, r21)) { double bx = r11; r11 = r21; r21 = bx; } - if(UbMath::greater(r12, r22)) { double by = r12; r12 = r22; r22 = by; } - if(UbMath::greater(r13, r23)) { double bz = r13; r13 = r23; r23 = bz; } - - double m11 = UbMath::greater(x11, r11) ? x11 : r11; - double m12 = UbMath::greater(x12, r12) ? x12 : r12; - double m13 = UbMath::greater(x13, r13) ? x13 : r13; - double m21 = UbMath::greater(x21, r21) ? r21 : x21; - double m22 = UbMath::greater(x22, r22) ? r22 : x22; - double m23 = UbMath::greater(x23, r23) ? r23 : x23; - - if(UbMath::lessEqual(m11, m21) && UbMath::lessEqual(m12, m22) && UbMath::lessEqual(m13, m23)) - return(new GbCuboid3D(new GbPoint3D(m11, m12, m13), new GbPoint3D(m21, m22, m23))); - else - return(NULL); + double r11 = p1.x1; + double r12 = p1.x2; + double r13 = p1.x3; + double r21 = p2.x1; + double r22 = p2.x2; + double r23 = p2.x3; + + if (UbMath::greater(x11, x21)) { + double ax = x11; + x11 = x21; + x21 = ax; + } + if (UbMath::greater(x12, x22)) { + double ay = x12; + x12 = x22; + x22 = ay; + } + if (UbMath::greater(x13, x23)) { + double az = x13; + x13 = x23; + x23 = az; + } + if (UbMath::greater(r11, r21)) { + double bx = r11; + r11 = r21; + r21 = bx; + } + if (UbMath::greater(r12, r22)) { + double by = r12; + r12 = r22; + r22 = by; + } + if (UbMath::greater(r13, r23)) { + double bz = r13; + r13 = r23; + r23 = bz; + } + + double m11 = UbMath::greater(x11, r11) ? x11 : r11; + double m12 = UbMath::greater(x12, r12) ? x12 : r12; + double m13 = UbMath::greater(x13, r13) ? x13 : r13; + double m21 = UbMath::greater(x21, r21) ? r21 : x21; + double m22 = UbMath::greater(x22, r22) ? r22 : x22; + double m23 = UbMath::greater(x23, r23) ? r23 : x23; + + if (UbMath::lessEqual(m11, m21) && UbMath::lessEqual(m12, m22) && UbMath::lessEqual(m13, m23)) + return (new GbCuboid3D(new GbPoint3D(m11, m12, m13), new GbPoint3D(m21, m22, m23))); + else + return (NULL); } /*=========================================================================*/ /*=========================================================================*/ /*=========================================================================*/ - GbSystem3D::PointSet3::PointSet3(int n) { - this->init(); - this->points.reserve(n); //reserves n elements! but the size of the vector ist still "0" + this->init(); + this->points.reserve(n); // reserves n elements! but the size of the vector ist still "0" } /*=======================================================*/ -GbSystem3D::PointSet3::PointSet3(const vector<GbPoint3D>& points) +GbSystem3D::PointSet3::PointSet3(const vector<GbPoint3D> &points) { - this->init(); - this->add(points); + this->init(); + this->add(points); } /*=======================================================*/ -void GbSystem3D::PointSet3::add(const GbPoint3D& point) +void GbSystem3D::PointSet3::add(const GbPoint3D &point) { - //is point equal to last point in points then return - if(!this->points.empty() && point.equals(&this->points.back())) return; //WHY??? + // is point equal to last point in points then return + if (!this->points.empty() && point.equals(&this->points.back())) + return; // WHY??? - //push point to vector - this->points.push_back(point); + // push point to vector + this->points.push_back(point); - this->consistent = false; + this->consistent = false; } /*=======================================================*/ -void GbSystem3D::PointSet3::addUnequal(const GbPoint3D& point) +void GbSystem3D::PointSet3::addUnequal(const GbPoint3D &point) { - if(this->containsEqual(point) > 0) return; - - this->points.push_back(point); - this->consistent = false; + if (this->containsEqual(point) > 0) + return; + + this->points.push_back(point); + this->consistent = false; } /*=======================================================*/ -void GbSystem3D::PointSet3::add(const vector<GbPoint3D>& pointVector) +void GbSystem3D::PointSet3::add(const vector<GbPoint3D> &pointVector) { - for(int pos=0; pos<(int)pointVector.size(); pos++ ) - this->points.push_back(pointVector[pos]); + for (int pos = 0; pos < (int)pointVector.size(); pos++) + this->points.push_back(pointVector[pos]); - this->consistent = false; + this->consistent = false; } /*=======================================================*/ -void GbSystem3D::PointSet3::insert(const GbPoint3D& point, int index) +void GbSystem3D::PointSet3::insert(const GbPoint3D &point, int index) { - if(index<0 || index>=(int)this->points.size()) - throw UbException(UB_EXARGS,"index out of range"); + if (index < 0 || index >= (int)this->points.size()) + throw UbException(UB_EXARGS, "index out of range"); - //get iterator for index-position - vector<GbPoint3D>::iterator pos=this->points.begin(); - for(int i=1; i<=index; i++) ++pos; + // get iterator for index-position + vector<GbPoint3D>::iterator pos = this->points.begin(); + for (int i = 1; i <= index; i++) + ++pos; - //insert point - this->points.insert(pos,point); + // insert point + this->points.insert(pos, point); - this->consistent = false; + this->consistent = false; } /*=======================================================*/ -//void delete(GbPoint3D point) +// void delete(GbPoint3D point) //{ // for(int i=this.size-1; i>=0; i--) if(this.points[i] == point) this.delete(i); //} /*=======================================================*/ -//void delete(int index) +// void delete(int index) //{ // int j = this.size - index - 1; // if(j > 0) System.arraycopy(this.points, index + 1, this.points, index, j); @@ -1043,176 +1107,177 @@ void GbSystem3D::PointSet3::insert(const GbPoint3D& point, int index) /*=======================================================*/ void GbSystem3D::PointSet3::clear() { - //clears points (size==0 but capacity is the old c1) - this->points.clear(); - this->consistent = false; + // clears points (size==0 but capacity is the old c1) + this->points.clear(); + this->consistent = false; } /*=======================================================*/ void GbSystem3D::PointSet3::clearAndTrim() { - //clears points (size==0 AND capacity==0) - this->points.resize(0); - this->consistent = false; + // clears points (size==0 AND capacity==0) + this->points.resize(0); + this->consistent = false; } /*=======================================================*/ double GbSystem3D::PointSet3::getX1Minimum() { - if(!this->consistent) this->calculateValues(); - return this->x1min; + if (!this->consistent) + this->calculateValues(); + return this->x1min; } /*=======================================================*/ double GbSystem3D::PointSet3::getX1Maximum() { - if(!this->consistent) this->calculateValues(); - return this->x1max; + if (!this->consistent) + this->calculateValues(); + return this->x1max; } /*=======================================================*/ double GbSystem3D::PointSet3::getX2Minimum() { - if(!this->consistent) this->calculateValues(); - return this->x2min; + if (!this->consistent) + this->calculateValues(); + return this->x2min; } /*=======================================================*/ double GbSystem3D::PointSet3::getX2Maximum() { - if(!this->consistent) this->calculateValues(); - return this->x2max; + if (!this->consistent) + this->calculateValues(); + return this->x2max; } /*=======================================================*/ double GbSystem3D::PointSet3::getX3Minimum() { - if(!this->consistent) this->calculateValues(); - return this->x3min; + if (!this->consistent) + this->calculateValues(); + return this->x3min; } /*=======================================================*/ double GbSystem3D::PointSet3::getX3Maximum() { - if(!this->consistent) this->calculateValues(); - return this->x3max; + if (!this->consistent) + this->calculateValues(); + return this->x3max; } /*=======================================================*/ -int GbSystem3D::PointSet3::contains(GbPoint3D* point) +int GbSystem3D::PointSet3::contains(GbPoint3D *point) { - //returns number of points which has the same adress (this should be 0 or 1!!!) - int n=0; + // returns number of points which has the same adress (this should be 0 or 1!!!) + int n = 0; - for(int pos=(int)this->points.size()-1; pos>=0; pos--) - if(&this->points[pos]==point) n++; + for (int pos = (int)this->points.size() - 1; pos >= 0; pos--) + if (&this->points[pos] == point) + n++; - return n; + return n; } /*=======================================================*/ -int GbSystem3D::PointSet3::containsEqual(const GbPoint3D& point) +int GbSystem3D::PointSet3::containsEqual(const GbPoint3D &point) { - //returns number of points which have the same coordinates with point (could be 0,1 or even more) - int n=0; + // returns number of points which have the same coordinates with point (could be 0,1 or even more) + int n = 0; - for(int pos=(int)this->points.size()-1; pos>=0; pos--) - if(this->points[pos].equals(&point)) n++; + for (int pos = (int)this->points.size() - 1; pos >= 0; pos--) + if (this->points[pos].equals(&point)) + n++; - return n; + return n; } /*=======================================================*/ bool GbSystem3D::PointSet3::containsLine(GbPoint3D *point1, GbPoint3D *point2) { - //returns true if pointset has c2 in "this->points"vector neighboured points - //wich have the same adress as point1 or point2 - vector<GbPoint3D>::iterator pos1=this->points.begin(); - vector<GbPoint3D>::iterator pos2; + // returns true if pointset has c2 in "this->points"vector neighboured points + // wich have the same adress as point1 or point2 + vector<GbPoint3D>::iterator pos1 = this->points.begin(); + vector<GbPoint3D>::iterator pos2; - for(pos2=pos1++; pos2!=this->points.end(); ++pos2) - { - if (&(*pos1)==point1 && &(*pos2)==point2) return true; - else if(&(*pos1)==point2 && &(*pos2)==point1) return true; + for (pos2 = pos1++; pos2 != this->points.end(); ++pos2) { + if (&(*pos1) == point1 && &(*pos2) == point2) + return true; + else if (&(*pos1) == point2 && &(*pos2) == point1) + return true; - pos1=pos2; - } + pos1 = pos2; + } - return false; + return false; } /*=======================================================*/ -bool GbSystem3D::PointSet3::containsEqualLine(const GbPoint3D& point1, const GbPoint3D& point2) +bool GbSystem3D::PointSet3::containsEqualLine(const GbPoint3D &point1, const GbPoint3D &point2) { - //returns true if pointset has c2 in "this->points"vector neighboured points - //wich have the same coordinates as point1 or point2 - vector<GbPoint3D>::iterator pos1=this->points.begin(); - vector<GbPoint3D>::iterator pos2; + // returns true if pointset has c2 in "this->points"vector neighboured points + // wich have the same coordinates as point1 or point2 + vector<GbPoint3D>::iterator pos1 = this->points.begin(); + vector<GbPoint3D>::iterator pos2; - for(pos2=pos1++; pos2!=this->points.end(); ++pos2) - { - if ((*pos1).equals(&point1) && (*pos2).equals(&point2)) return true; - else if((*pos1).equals(&point2) && (*pos2).equals(&point1)) return true; + for (pos2 = pos1++; pos2 != this->points.end(); ++pos2) { + if ((*pos1).equals(&point1) && (*pos2).equals(&point2)) + return true; + else if ((*pos1).equals(&point2) && (*pos2).equals(&point1)) + return true; - pos1=pos2; - } + pos1 = pos2; + } - return false; + return false; } /*=======================================================*/ -GbPoint3D* GbSystem3D::PointSet3::getPoint(int index) +GbPoint3D *GbSystem3D::PointSet3::getPoint(int index) { - if(index<0 || index>=(int)this->points.size()) throw UbException(UB_EXARGS,"index out of range"); - return &(this->points)[index]; + if (index < 0 || index >= (int)this->points.size()) + throw UbException(UB_EXARGS, "index out of range"); + return &(this->points)[index]; } /*=======================================================*/ -GbPoint3D* GbSystem3D::PointSet3::getFirstPoint() -{ - return &(this->points.front()); -} +GbPoint3D *GbSystem3D::PointSet3::getFirstPoint() { return &(this->points.front()); } /*=======================================================*/ -GbPoint3D* GbSystem3D::PointSet3::getLastPoint() -{ - return &(this->points.back()); -} +GbPoint3D *GbSystem3D::PointSet3::getLastPoint() { return &(this->points.back()); } /*=======================================================*/ -int GbSystem3D::PointSet3::size() -{ - return (int)this->points.size(); -} +int GbSystem3D::PointSet3::size() { return (int)this->points.size(); } /*=======================================================*/ vector<GbPoint3D> GbSystem3D::PointSet3::getPoints() { - //is this right? it's another effect as at GbPoint3D* getNode(index)!!! - //or do we want to have the next uncommented getPoints() funktion - return this->points; + // is this right? it's another effect as at GbPoint3D* getNode(index)!!! + // or do we want to have the next uncommented getPoints() funktion + return this->points; } ///*=======================================================*/ -//vector<GbPoint3D*> GbSystem3D::PointSet3::getPoints() +// vector<GbPoint3D*> GbSystem3D::PointSet3::getPoints() //{ // vector<GbPoint3D*> tmp; // for(int pos=0; pos<(int)this->points.size();pos++) tmp.push_back(&this->points[pos]); -// +// // return tmp; //} /*=======================================================*/ void GbSystem3D::PointSet3::calculateValues() { - if(this->points.empty()) - { - this->x1min = this->x2min = this->x3min = 0.0; - this->x1max = this->x2max = this->x3max = 0.0; - } - else - { - this->x1min = (this->points)[0].x1; - this->x1max = (this->points)[0].x1; - this->x2min = (this->points)[0].x2; - this->x2max = (this->points)[0].x2; - this->x3min = (this->points)[0].x3; - this->x3max = (this->points)[0].x3; - - for(int i=(int)this->points.size()-1; i>0; --i) - { - if((this->points)[i].x1 < this->x1min) this->x1min = (this->points)[i].x1; - if((this->points)[i].x1 > this->x1max) this->x1max = (this->points)[i].x1; - if((this->points)[i].x2 < this->x2min) this->x2min = (this->points)[i].x2; - if((this->points)[i].x2 > this->x2max) this->x2max = (this->points)[i].x2; - if((this->points)[i].x3 < this->x3min) this->x3min = (this->points)[i].x3; - if((this->points)[i].x3 > this->x3max) this->x3max = (this->points)[i].x3; - } - } - this->consistent = true; + if (this->points.empty()) { + this->x1min = this->x2min = this->x3min = 0.0; + this->x1max = this->x2max = this->x3max = 0.0; + } else { + this->x1min = (this->points)[0].x1; + this->x1max = (this->points)[0].x1; + this->x2min = (this->points)[0].x2; + this->x2max = (this->points)[0].x2; + this->x3min = (this->points)[0].x3; + this->x3max = (this->points)[0].x3; + + for (int i = (int)this->points.size() - 1; i > 0; --i) { + if ((this->points)[i].x1 < this->x1min) + this->x1min = (this->points)[i].x1; + if ((this->points)[i].x1 > this->x1max) + this->x1max = (this->points)[i].x1; + if ((this->points)[i].x2 < this->x2min) + this->x2min = (this->points)[i].x2; + if ((this->points)[i].x2 > this->x2max) + this->x2max = (this->points)[i].x2; + if ((this->points)[i].x3 < this->x3min) + this->x3min = (this->points)[i].x3; + if ((this->points)[i].x3 > this->x3max) + this->x3max = (this->points)[i].x3; + } + } + this->consistent = true; } - - - diff --git a/src/basics/geometry3d/GbSystem3D.h b/src/basics/geometry3d/GbSystem3D.h index b448335ca..239a4c30d 100644 --- a/src/basics/geometry3d/GbSystem3D.h +++ b/src/basics/geometry3d/GbSystem3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,12 +33,12 @@ #ifndef GBSYSTEM3D_H #define GBSYSTEM3D_H -#include <iostream> #include <cmath> +#include <iostream> #include <vector> -#include <GbPoint3D.h> #include <GbObject3D.h> +#include <GbPoint3D.h> #include <basics/utilities/UbMath.h> #include <basics/writer/WbWriter.h> @@ -48,372 +48,393 @@ class GbLine3D; namespace GbSystem3D { - extern double getDistance(const GbPoint3D& p11, const GbPoint3D& p12); - extern GbPoint3D* calculateIntersectionPoint3D(GbPoint3D& p11, GbPoint3D& p12, GbPoint3D& p21, GbPoint3D& p22); - extern GbPolygon3D* clipPolygon3D(std::vector<GbPoint3D> points, double x11, double x12, double x13, double x21, double x22, double x23); - extern GbLine3D* createClipLine3D(GbPoint3D& p1, GbPoint3D& p2, double x11, double x12, double x13, double x21, double x22, double x23); - extern bool hasIntersectionPoint3D(GbPoint3D& p11, GbPoint3D& p12, GbPoint3D& p21, GbPoint3D& p22); - extern bool isParallelIn3D(GbPoint3D& p11, GbPoint3D& p12, GbPoint3D& p21, GbPoint3D& p22); - extern GbCuboid3D* clipRectangle3D(GbPoint3D& p1, GbPoint3D& p2, double x11, double x12, double x13, double x21, double x22, double x23); +extern double getDistance(const GbPoint3D &p11, const GbPoint3D &p12); +extern GbPoint3D *calculateIntersectionPoint3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22); +extern GbPolygon3D *clipPolygon3D(std::vector<GbPoint3D> points, double x11, double x12, double x13, double x21, + double x22, double x23); +extern GbLine3D *createClipLine3D(GbPoint3D &p1, GbPoint3D &p2, double x11, double x12, double x13, double x21, + double x22, double x23); +extern bool hasIntersectionPoint3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22); +extern bool isParallelIn3D(GbPoint3D &p11, GbPoint3D &p12, GbPoint3D &p21, GbPoint3D &p22); +extern GbCuboid3D *clipRectangle3D(GbPoint3D &p1, GbPoint3D &p2, double x11, double x12, double x13, double x21, + double x22, double x23); - /*========================================================================================*/ - inline static std::string writeGeoObject(GbObject3D* gbobject, const std::string& filename, WbWriter* writer) - { - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleInt3> triangles; - gbobject->addSurfaceTriangleSet(nodes, triangles); +/*========================================================================================*/ +inline static std::string writeGeoObject(GbObject3D *gbobject, const std::string &filename, WbWriter *writer) +{ + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt3> triangles; + gbobject->addSurfaceTriangleSet(nodes, triangles); - std::string outFilename = writer->writeTriangles(filename,nodes,triangles); - return outFilename; - } - //the same as before - /*========================================================================================*/ - inline static std::string writeGeoObject(SPtr<GbObject3D> gbobject, const std::string& filename, WbWriter* writer) - { - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleInt3> triangles; - gbobject->addSurfaceTriangleSet(nodes, triangles); + std::string outFilename = writer->writeTriangles(filename, nodes, triangles); + return outFilename; +} +// the same as before +/*========================================================================================*/ +inline static std::string writeGeoObject(SPtr<GbObject3D> gbobject, const std::string &filename, WbWriter *writer) +{ + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt3> triangles; + gbobject->addSurfaceTriangleSet(nodes, triangles); - std::string outFilename = writer->writeTriangles(filename,nodes,triangles); - return outFilename; - } - /*========================================================================================*/ - inline static std::vector< std::string > writeGeoObject(GbObject3D* gbobject, const std::string& filename, std::vector< WbWriter* > writer ) - { - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleInt3> triangles; - gbobject->addSurfaceTriangleSet(nodes, triangles); + std::string outFilename = writer->writeTriangles(filename, nodes, triangles); + return outFilename; +} +/*========================================================================================*/ +inline static std::vector<std::string> writeGeoObject(GbObject3D *gbobject, const std::string &filename, + std::vector<WbWriter *> writer) +{ + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt3> triangles; + gbobject->addSurfaceTriangleSet(nodes, triangles); - std::vector< std::string > outFilenames; - for(std::size_t i=0; i<writer.size(); ++i) - outFilenames.push_back( writer[i]->writeTriangles(filename,nodes,triangles) ); - return outFilenames; - } - /*========================================================================================*/ - inline static std::string writeGeoObjects(std::vector< GbObject3D* > gbobjects, const std::string& filename, WbWriter* writer) - { - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleInt3> triangles; + std::vector<std::string> outFilenames; + for (std::size_t i = 0; i < writer.size(); ++i) + outFilenames.push_back(writer[i]->writeTriangles(filename, nodes, triangles)); + return outFilenames; +} +/*========================================================================================*/ +inline static std::string writeGeoObjects(std::vector<GbObject3D *> gbobjects, const std::string &filename, + WbWriter *writer) +{ + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt3> triangles; - for(std::size_t i=0; i<gbobjects.size(); ++i) - { - //std::cout<<i<<", "<<gbobjects[i]<<std::endl; - gbobjects[i]->addSurfaceTriangleSet(nodes, triangles); - } + for (std::size_t i = 0; i < gbobjects.size(); ++i) { + // std::cout<<i<<", "<<gbobjects[i]<<std::endl; + gbobjects[i]->addSurfaceTriangleSet(nodes, triangles); + } - std::string outFilename = writer->writeTriangles(filename,nodes,triangles); - return outFilename; - } - /*========================================================================================*/ + std::string outFilename = writer->writeTriangles(filename, nodes, triangles); + return outFilename; +} +/*========================================================================================*/ - ////////////////////////////////////////////////////////////////////////// - class PointSet3 - { - public: - PointSet3(int n); - PointSet3(const std::vector<GbPoint3D>& points); - ~PointSet3()= default; - void add(const GbPoint3D& point); - void addUnequal(const GbPoint3D& point); - void add(const std::vector<GbPoint3D>& p); - int contains(GbPoint3D* point); - void insert(const GbPoint3D& point, int index); - void clear(); - void clearAndTrim(); - int containsEqual(const GbPoint3D& point); - bool containsLine(GbPoint3D* point1, GbPoint3D* point2); - bool containsEqualLine(const GbPoint3D& point1, const GbPoint3D& point2); - double getX1Minimum(); - double getX1Maximum(); - double getX2Minimum(); - double getX2Maximum(); - double getX3Minimum(); - double getX3Maximum(); - void calculateValues(); - int size(); - GbPoint3D* getPoint(int index); - GbPoint3D* getFirstPoint(); - GbPoint3D* getLastPoint() ; - std::vector<GbPoint3D> getPoints(); +////////////////////////////////////////////////////////////////////////// +class PointSet3 +{ +public: + PointSet3(int n); + PointSet3(const std::vector<GbPoint3D> &points); + ~PointSet3() = default; + void add(const GbPoint3D &point); + void addUnequal(const GbPoint3D &point); + void add(const std::vector<GbPoint3D> &p); + int contains(GbPoint3D *point); + void insert(const GbPoint3D &point, int index); + void clear(); + void clearAndTrim(); + int containsEqual(const GbPoint3D &point); + bool containsLine(GbPoint3D *point1, GbPoint3D *point2); + bool containsEqualLine(const GbPoint3D &point1, const GbPoint3D &point2); + double getX1Minimum(); + double getX1Maximum(); + double getX2Minimum(); + double getX2Maximum(); + double getX3Minimum(); + double getX3Maximum(); + void calculateValues(); + int size(); + GbPoint3D *getPoint(int index); + GbPoint3D *getFirstPoint(); + GbPoint3D *getLastPoint(); + std::vector<GbPoint3D> getPoints(); - private: - double x1min; - double x1max; - double x2min; - double x2max; - double x3min; - double x3max; - bool consistent; - std::vector<GbPoint3D> points; +private: + double x1min; + double x1max; + double x2min; + double x2max; + double x3min; + double x3max; + bool consistent; + std::vector<GbPoint3D> points; - void init() - { - consistent = false; - x1min = x2min = x3min = 0.0; - x1max = x2max = x3max = 0.0; - } - }; - /*=================================================================*/ - class OldPointSet3 - { - private: - int sizet; - double x1min; - double x1max; - double x2min; - double x2max; - double x3min; - double x3max; - bool consistent; - std::vector<GbPoint3D> points; + void init() + { + consistent = false; + x1min = x2min = x3min = 0.0; + x1max = x2max = x3max = 0.0; + } +}; +/*=================================================================*/ +class OldPointSet3 +{ +private: + int sizet; + double x1min; + double x1max; + double x2min; + double x2max; + double x3min; + double x3max; + bool consistent; + std::vector<GbPoint3D> points; - void init() - { - sizet = 0; - x1min = 0.0; - x1max = 0.0; - x2min = 0.0; - x2max = 0.0; - x3min = 0.0; - x3max = 0.0; - consistent = false; - //points = NULL; - }; + void init() + { + sizet = 0; + x1min = 0.0; + x1max = 0.0; + x2min = 0.0; + x2max = 0.0; + x3min = 0.0; + x3max = 0.0; + consistent = false; + // points = NULL; + }; - public: - OldPointSet3(int n) - { - this->init(); - this->points.resize(n); - } - OldPointSet3(std::vector<GbPoint3D> &points) - { - this->init(); - this->points.resize(0);//, NULL); - this->add(points); - }; - ~OldPointSet3() = default; - void add(GbPoint3D point) - { - if(this->sizet>0 && point.equals(&(this->points)[this->sizet-1])) return; - if(this->sizet == (int)this->points.size()) - { - std::vector<GbPoint3D> a; - a.resize(1+(this->sizet<<1)); - for(int u=0; u<this->sizet; u++) { (a)[u] = (points)[u]; } - this->points = a; +public: + OldPointSet3(int n) + { + this->init(); + this->points.resize(n); + } + OldPointSet3(std::vector<GbPoint3D> &points) + { + this->init(); + this->points.resize(0); //, NULL); + this->add(points); + }; + ~OldPointSet3() = default; + void add(GbPoint3D point) + { + if (this->sizet > 0 && point.equals(&(this->points)[this->sizet - 1])) + return; + if (this->sizet == (int)this->points.size()) { + std::vector<GbPoint3D> a; + a.resize(1 + (this->sizet << 1)); + for (int u = 0; u < this->sizet; u++) { + (a)[u] = (points)[u]; } - (this->points)[this->sizet] = point; - this->consistent = false; - this->sizet++; - } - void addUnequal(GbPoint3D *point) - { - if(this->containsEqual(point) > 0) return; - if(this->sizet == (int)this->points.size()) - { - std::vector<GbPoint3D> a; - a.resize(1+(this->sizet<<1)); - for(int u=0; u<this->sizet; u++) { (a)[u] = (points)[u]; } - this->points = a; + this->points = a; + } + (this->points)[this->sizet] = point; + this->consistent = false; + this->sizet++; + } + void addUnequal(GbPoint3D *point) + { + if (this->containsEqual(point) > 0) + return; + if (this->sizet == (int)this->points.size()) { + std::vector<GbPoint3D> a; + a.resize(1 + (this->sizet << 1)); + for (int u = 0; u < this->sizet; u++) { + (a)[u] = (points)[u]; } - (this->points)[this->sizet] = point; - this->consistent = false; - this->sizet++; - } - void add(std::vector<GbPoint3D> &p) - { - if(this->sizet+p.size() >= this->points.size()) - { - std::vector<GbPoint3D> a; - a.resize(this->sizet+p.size()); - for(int u=0; u<(int)this->points.size(); u++) { (a)[u] = (this->points)[u]; } - this->points = a; + this->points = a; + } + (this->points)[this->sizet] = point; + this->consistent = false; + this->sizet++; + } + void add(std::vector<GbPoint3D> &p) + { + if (this->sizet + p.size() >= this->points.size()) { + std::vector<GbPoint3D> a; + a.resize(this->sizet + p.size()); + for (int u = 0; u < (int)this->points.size(); u++) { + (a)[u] = (this->points)[u]; } - int u = this->sizet;// (int)this->points->size(); - for(int b=0; b<(int)p.size(); b++) (this->points)[u++] = (p)[b]; - //u = this->sizet; - //for(int b=0; b<(int)p->size(); b++) - // cout<<(this->points)[u++].toString()<<endl; - this->consistent = false; - this->sizet += (int)p.size(); - }; - // void insert(GbPoint3D *point, int index) - // { - // if(this.size == this.points.length) - // { - // GbPoint3D a[] = new GbPoint3D[1+(this.size<<1)]; - // System.arraycopy(this.points, 0, a, 0, this.size); - // this.points = a; - // } - // System.arraycopy(this.points, index, this.points, index+1, this.size-index); - // this.points[index] = point; - // this.consistent = false; - // this.size++; - // } - // void delete(GbPoint3D point) - // { - // for(int i=this.size-1; i>=0; i--) if(this.points[i] == point) this.delete(i); - // } - // void delete(int index) - // { - // int j = this.size - index - 1; - // if(j > 0) System.arraycopy(this.points, index + 1, this.points, index, j); - // this.consistent = false; - // this.size--; - // } - void clear() - { - this->sizet = 0; - this->consistent = false; - } - void clearAndTrim() - { - this->sizet = 0; - this->points.resize(0); - this->consistent = false; - } + this->points = a; + } + int u = this->sizet; // (int)this->points->size(); + for (int b = 0; b < (int)p.size(); b++) + (this->points)[u++] = (p)[b]; + // u = this->sizet; + // for(int b=0; b<(int)p->size(); b++) + // cout<<(this->points)[u++].toString()<<endl; + this->consistent = false; + this->sizet += (int)p.size(); + }; + // void insert(GbPoint3D *point, int index) + // { + // if(this.size == this.points.length) + // { + // GbPoint3D a[] = new GbPoint3D[1+(this.size<<1)]; + // System.arraycopy(this.points, 0, a, 0, this.size); + // this.points = a; + // } + // System.arraycopy(this.points, index, this.points, index+1, this.size-index); + // this.points[index] = point; + // this.consistent = false; + // this.size++; + // } + // void delete(GbPoint3D point) + // { + // for(int i=this.size-1; i>=0; i--) if(this.points[i] == point) this.delete(i); + // } + // void delete(int index) + // { + // int j = this.size - index - 1; + // if(j > 0) System.arraycopy(this.points, index + 1, this.points, index, j); + // this.consistent = false; + // this.size--; + // } + void clear() + { + this->sizet = 0; + this->consistent = false; + } + void clearAndTrim() + { + this->sizet = 0; + this->points.resize(0); + this->consistent = false; + } - double getX1Minimum() - { - if(!this->consistent) this->calculateValues(); - return(this->x1min); - } - double getX1Maximum() - { - if(!this->consistent) this->calculateValues(); - return(this->x1max); - } - double getX2Minimum() - { - if(!this->consistent) this->calculateValues(); - return(this->x2min); - } - double getX2Maximum() - { - if(!this->consistent) this->calculateValues(); - return(this->x2max); - } - double getX3Minimum() - { - if(!this->consistent) this->calculateValues(); - return(this->x3min); - } - double getX3Maximum() - { - if(!this->consistent) this->calculateValues(); - return(this->x3max); - } - void calculateValues() - { - this->x1min = 0.0; - this->x1max = 0.0; - this->x2min = 0.0; - this->x2max = 0.0; - this->x3min = 0.0; - this->x3max = 0.0; - this->consistent = true; + double getX1Minimum() + { + if (!this->consistent) + this->calculateValues(); + return (this->x1min); + } + double getX1Maximum() + { + if (!this->consistent) + this->calculateValues(); + return (this->x1max); + } + double getX2Minimum() + { + if (!this->consistent) + this->calculateValues(); + return (this->x2min); + } + double getX2Maximum() + { + if (!this->consistent) + this->calculateValues(); + return (this->x2max); + } + double getX3Minimum() + { + if (!this->consistent) + this->calculateValues(); + return (this->x3min); + } + double getX3Maximum() + { + if (!this->consistent) + this->calculateValues(); + return (this->x3max); + } + void calculateValues() + { + this->x1min = 0.0; + this->x1max = 0.0; + this->x2min = 0.0; + this->x2max = 0.0; + this->x3min = 0.0; + this->x3max = 0.0; + this->consistent = true; - if(this->sizet == 0) return; + if (this->sizet == 0) + return; - this->x1min = (this->points)[0].x1; - this->x1max = (this->points)[0].x1; - this->x2min = (this->points)[0].x2; - this->x2max = (this->points)[0].x2; - this->x3min = (this->points)[0].x3; - this->x3max = (this->points)[0].x3; + this->x1min = (this->points)[0].x1; + this->x1max = (this->points)[0].x1; + this->x2min = (this->points)[0].x2; + this->x2max = (this->points)[0].x2; + this->x3min = (this->points)[0].x3; + this->x3max = (this->points)[0].x3; - for(int i=this->sizet-1; i>0; i--) - { - if((this->points)[i].x1 < this->x1min) this->x1min = (this->points)[i].x1; - if((this->points)[i].x1 > this->x1max) this->x1max = (this->points)[i].x1; - if((this->points)[i].x2 < this->x2min) this->x2min = (this->points)[i].x2; - if((this->points)[i].x2 > this->x2max) this->x2max = (this->points)[i].x2; - if((this->points)[i].x3 < this->x3min) this->x3min = (this->points)[i].x3; - if((this->points)[i].x3 > this->x3max) this->x3max = (this->points)[i].x3; - } - }; + for (int i = this->sizet - 1; i > 0; i--) { + if ((this->points)[i].x1 < this->x1min) + this->x1min = (this->points)[i].x1; + if ((this->points)[i].x1 > this->x1max) + this->x1max = (this->points)[i].x1; + if ((this->points)[i].x2 < this->x2min) + this->x2min = (this->points)[i].x2; + if ((this->points)[i].x2 > this->x2max) + this->x2max = (this->points)[i].x2; + if ((this->points)[i].x3 < this->x3min) + this->x3min = (this->points)[i].x3; + if ((this->points)[i].x3 > this->x3max) + this->x3max = (this->points)[i].x3; + } + }; - int contains(GbPoint3D *point) - { - int n = 0; - for(int i=this->sizet-1; i>=0; i--) if(&(this->points)[i] == point) n++; - return(n); - }; - int containsEqual(GbPoint3D *point) - { - int n = 0; - for(int i=this->sizet-1; i>=0; i--) if((this->points)[i].equals(point)) n++; - return(n); - } - bool containsLine(GbPoint3D *point1, GbPoint3D *point2) - { - for(int i=this->sizet-1; i>=0; i--) if(&(this->points)[i] == point1) - { - if(i == 0) - { - if(&(this->points)[i+1] == point2) return(true); - if(&(this->points)[this->sizet-1] == point2) return(true); - } - else if(i == this->sizet-1) - { - if(&(this->points)[0] == point2) return(true); - if(&(this->points)[i-1] == point2) return(true); - } - else - { - if(&(this->points)[i+1] == point2) return(true); - if(&(this->points)[i-1] == point2) return(true); - } + int contains(GbPoint3D *point) + { + int n = 0; + for (int i = this->sizet - 1; i >= 0; i--) + if (&(this->points)[i] == point) + n++; + return (n); + }; + int containsEqual(GbPoint3D *point) + { + int n = 0; + for (int i = this->sizet - 1; i >= 0; i--) + if ((this->points)[i].equals(point)) + n++; + return (n); + } + bool containsLine(GbPoint3D *point1, GbPoint3D *point2) + { + for (int i = this->sizet - 1; i >= 0; i--) + if (&(this->points)[i] == point1) { + if (i == 0) { + if (&(this->points)[i + 1] == point2) + return (true); + if (&(this->points)[this->sizet - 1] == point2) + return (true); + } else if (i == this->sizet - 1) { + if (&(this->points)[0] == point2) + return (true); + if (&(this->points)[i - 1] == point2) + return (true); + } else { + if (&(this->points)[i + 1] == point2) + return (true); + if (&(this->points)[i - 1] == point2) + return (true); + } } - return(false); - }; - // boolean containsEqualLine(GbPoint2D point1, GbPoint2D point2) - // { - // for(int i=this.size-1; i>=0; i--) if(this.points[i].equals(point1)) - // { - // if(i == 0) - // { - // if(this.points[i+1].equals(point2)) return(true); - // if(this.points[this.size-1].equals(point2)) return(true); - // } - // else if(i == this.size-1) - // { - // if(this.points[0].equals(point2)) return(true); - // if(this.points[i-1].equals(point2)) return(true); - // } - // else - // { - // if(this.points[i+1].equals(point2)) return(true); - // if(this.points[i-1].equals(point2)) return(true); - // } - // } - // return(false); - // } - GbPoint3D *getPoint(int index) - { - return(&(this->points)[index]); - } - GbPoint3D *getFirstPoint() - { - return(&(this->points)[0]); - } - GbPoint3D *getLastPoint() { return(&(this->points)[this->sizet-1]); } - int size() { return(this->sizet); } - std::vector<GbPoint3D> getPoints() - { - points.resize(sizet); - return points; - //int l = this->sizet; - //if(l > 1 && (this->points)[0].equals(&(this->points)[l-1])) l--; + return (false); + }; + // boolean containsEqualLine(GbPoint2D point1, GbPoint2D point2) + // { + // for(int i=this.size-1; i>=0; i--) if(this.points[i].equals(point1)) + // { + // if(i == 0) + // { + // if(this.points[i+1].equals(point2)) return(true); + // if(this.points[this.size-1].equals(point2)) return(true); + // } + // else if(i == this.size-1) + // { + // if(this.points[0].equals(point2)) return(true); + // if(this.points[i-1].equals(point2)) return(true); + // } + // else + // { + // if(this.points[i+1].equals(point2)) return(true); + // if(this.points[i-1].equals(point2)) return(true); + // } + // } + // return(false); + // } + GbPoint3D *getPoint(int index) { return (&(this->points)[index]); } + GbPoint3D *getFirstPoint() { return (&(this->points)[0]); } + GbPoint3D *getLastPoint() { return (&(this->points)[this->sizet - 1]); } + int size() { return (this->sizet); } + std::vector<GbPoint3D> getPoints() + { + points.resize(sizet); + return points; + // int l = this->sizet; + // if(l > 1 && (this->points)[0].equals(&(this->points)[l-1])) l--; - //vector<GbPoint3D*> *a = new vector<GbPoint3D*>; - //a->resize(l, NULL); - //for(int u=0; u<l; u++) { (*a)[u] = &((points)[u]); } - //return(a); - } - }; - /*=================================================================*/ -} + // vector<GbPoint3D*> *a = new vector<GbPoint3D*>; + // a->resize(l, NULL); + // for(int u=0; u<l; u++) { (*a)[u] = &((points)[u]); } + // return(a); + } +}; +/*=================================================================*/ +} // namespace GbSystem3D -#endif //GBSYSTEM3D_H +#endif // GBSYSTEM3D_H diff --git a/src/basics/geometry3d/GbTriangle3D.cpp b/src/basics/geometry3d/GbTriangle3D.cpp index 51edfa5ea..3b5a96af7 100644 --- a/src/basics/geometry3d/GbTriangle3D.cpp +++ b/src/basics/geometry3d/GbTriangle3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,489 +30,531 @@ //! \ingroup geometry3d //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#include <GbTriangle3D.h> -#include <GbSystem3D.h> -#include <GbLine3D.h> #include <GbCuboid3D.h> +#include <GbLine3D.h> +#include <GbSystem3D.h> +#include <GbTriangle3D.h> #include <basics/utilities/UbMath.h> -using namespace std; +using namespace std; GbTriangle3D::GbTriangle3D() { - this->init(); - this->consistent = false; + this->init(); + this->consistent = false; } /*======================================================================*/ /* -* Creates an empty 2D triangle with the specified points. -* @param point1 the 1st point -* @param point2 the 2nd point -* @param point3 the 3nd point -*/ -GbTriangle3D::GbTriangle3D(GbPoint3D* point1, GbPoint3D* point2, GbPoint3D* point3) + * Creates an empty 2D triangle with the specified points. + * @param point1 the 1st point + * @param point2 the 2nd point + * @param point3 the 3nd point + */ +GbTriangle3D::GbTriangle3D(GbPoint3D *point1, GbPoint3D *point2, GbPoint3D *point3) { - this->init(); - this->points[0] = point1; - this->points[1] = point2; - this->points[2] = point3; - - this->calculateNormal(); - this->consistent = false; - - this->points[0]->addObserver(this); - this->points[1]->addObserver(this); - this->points[2]->addObserver(this); - - //this.po = new PointObserver(this); - //this.points[0].addObserver(this.po); - //this.points[1].addObserver(this.po); - //this.points[2].addObserver(this.po); + this->init(); + this->points[0] = point1; + this->points[1] = point2; + this->points[2] = point3; + + this->calculateNormal(); + this->consistent = false; + + this->points[0]->addObserver(this); + this->points[1]->addObserver(this); + this->points[2]->addObserver(this); + + // this.po = new PointObserver(this); + // this.points[0].addObserver(this.po); + // this.points[1].addObserver(this.po); + // this.points[2].addObserver(this.po); } /*======================================================================*/ /* -* Creates a 3D triangle as clone of the specified 2D triangle. -* @param triangle the 3D triangle to be cloned -*/ -GbTriangle3D::GbTriangle3D(GbTriangle3D* triangle) + * Creates a 3D triangle as clone of the specified 2D triangle. + * @param triangle the 3D triangle to be cloned + */ +GbTriangle3D::GbTriangle3D(GbTriangle3D *triangle) { - this->init(); - this->points[0] = triangle->points[0]->clone(); - this->points[1] = triangle->points[1]->clone(); - this->points[2] = triangle->points[2]->clone(); - - this->consistent = false; - this->calculateNormal(); - this->calculateValues(); + this->init(); + this->points[0] = triangle->points[0]->clone(); + this->points[1] = triangle->points[1]->clone(); + this->points[2] = triangle->points[2]->clone(); + + this->consistent = false; + this->calculateNormal(); + this->calculateValues(); } /*======================================================================*/ GbTriangle3D::~GbTriangle3D() { - if(this->points[0]) this->points[0]->removeObserver(this); - if(this->points[1]) this->points[1]->removeObserver(this); - if(this->points[2]) this->points[2]->removeObserver(this); + if (this->points[0]) + this->points[0]->removeObserver(this); + if (this->points[1]) + this->points[1]->removeObserver(this); + if (this->points[2]) + this->points[2]->removeObserver(this); } /*======================================================================*/ void GbTriangle3D::deletePoints() -{ - if(points[0]) { delete points[0]; points[0]=NULL;} - if(points[1]) { delete points[1]; points[1]=NULL;} - if(points[2]) { delete points[2]; points[2]=NULL;} +{ + if (points[0]) { + delete points[0]; + points[0] = NULL; + } + if (points[1]) { + delete points[1]; + points[1] = NULL; + } + if (points[2]) { + delete points[2]; + points[2] = NULL; + } } /*======================================================================*/ /* Methoden */ /* */ /* -* Creates a 3D triangle as clone of this 3D triangle. -*/ -GbTriangle3D* GbTriangle3D::clone() -{ - return(new GbTriangle3D(this)); -} + * Creates a 3D triangle as clone of this 3D triangle. + */ +GbTriangle3D *GbTriangle3D::clone() { return (new GbTriangle3D(this)); } /*======================================================================*/ /* -* Returns the number of times this 2D triangle contains the specified point. -* @param point the point -* @return the number of times this 2D triangle contains the specified point -*/ -int GbTriangle3D::contains(GbPoint3D* point) + * Returns the number of times this 2D triangle contains the specified point. + * @param point the point + * @return the number of times this 2D triangle contains the specified point + */ +int GbTriangle3D::contains(GbPoint3D *point) { - int n = 0; - for(int i=0; i<3; i++) if(this->points[i]->equals(point)) n++; - return(n); + int n = 0; + for (int i = 0; i < 3; i++) + if (this->points[i]->equals(point)) + n++; + return (n); } /*======================================================================*/ /* -* Returns the number of times this 2D triangle contains a point equal to the specified point. -* @param point the point -* @return the number of times this 2D triangle contains a point equal to the specified point -*/ -int GbTriangle3D::containsEqual(GbPoint3D* point) + * Returns the number of times this 2D triangle contains a point equal to the specified point. + * @param point the point + * @return the number of times this 2D triangle contains a point equal to the specified point + */ +int GbTriangle3D::containsEqual(GbPoint3D *point) { - int n = 0; - for(int i=0; i<3; i++) if(this->points[i]->equals(point)) n++; - return(n); + int n = 0; + for (int i = 0; i < 3; i++) + if (this->points[i]->equals(point)) + n++; + return (n); } /*======================================================================*/ /* -* Returns the specified point. -* @param index the index (must be 0, 1, or 2) -* @return the specified point -* @exception ArrayIndexOutOfBoundsException if the specified index is not valid -*/ -GbPoint3D* GbTriangle3D::getPoint(const int& index) + * Returns the specified point. + * @param index the index (must be 0, 1, or 2) + * @return the specified point + * @exception ArrayIndexOutOfBoundsException if the specified index is not valid + */ +GbPoint3D *GbTriangle3D::getPoint(const int &index) { - if(index < 0 || index > 2) throw UbException(UB_EXARGS,"invalid index specified: "); - return((this->points[index])); + if (index < 0 || index > 2) + throw UbException(UB_EXARGS, "invalid index specified: "); + return ((this->points[index])); } /*======================================================================*/ -vector<GbPoint3D> GbTriangle3D::getPoints() +vector<GbPoint3D> GbTriangle3D::getPoints() { - vector<GbPoint3D> p(3); - p[0] = *(points[0]); - p[1] = *(points[1]); - p[2] = *(points[2]); - return p; - // - //vector<GbPoint3D> p(3);// = new vector<GbPoint3D*>; - //p.resize(3);//, NULL); - //p[0] = this->points[0]; - //p[1] = this->points[1]; - //p[2] = this->points[2]; - //return(p); + vector<GbPoint3D> p(3); + p[0] = *(points[0]); + p[1] = *(points[1]); + p[2] = *(points[2]); + return p; + // + // vector<GbPoint3D> p(3);// = new vector<GbPoint3D*>; + // p.resize(3);//, NULL); + // p[0] = this->points[0]; + // p[1] = this->points[1]; + // p[2] = this->points[2]; + // return(p); } /*======================================================================*/ /* -* Returns the area of this triangle. -* The area is positive for positive ordered points, otherwise negative. -* @return the area of this triangle -*/ + * Returns the area of this triangle. + * The area is positive for positive ordered points, otherwise negative. + * @return the area of this triangle + */ double GbTriangle3D::getArea() { - if(!this->consistent) this->calculateValues(); - // throw UbException(UB_EXARGS,"not correct calculated ..."); - return(this->area); + if (!this->consistent) + this->calculateValues(); + // throw UbException(UB_EXARGS,"not correct calculated ..."); + return (this->area); } /* -* Returns the centroid x1 coordinate of this triangle. -* @return the centroid x1 coordinate of this triangle -*/ + * Returns the centroid x1 coordinate of this triangle. + * @return the centroid x1 coordinate of this triangle + */ double GbTriangle3D::getX1Centroid() { - if(!this->consistent) this->calculateValues(); - return(this->x1s); + if (!this->consistent) + this->calculateValues(); + return (this->x1s); } /* -* Returns the minimum x1 coordinate of this triangle. -* @return the minimum x1 coordinate of this triangle -*/ + * Returns the minimum x1 coordinate of this triangle. + * @return the minimum x1 coordinate of this triangle + */ double GbTriangle3D::getX1Minimum() { - if(!this->consistent) this->calculateValues(); - return(this->x1min); + if (!this->consistent) + this->calculateValues(); + return (this->x1min); } /* -* Returns the maximum x1 coordinate of this triangle. -* @return the maximum x1 coordinate of this triangle -*/ + * Returns the maximum x1 coordinate of this triangle. + * @return the maximum x1 coordinate of this triangle + */ double GbTriangle3D::getX1Maximum() { - if(!this->consistent) this->calculateValues(); - return(this->x1max); + if (!this->consistent) + this->calculateValues(); + return (this->x1max); } /* -* Returns the centroid x2 coordinate of this triangle. -* @return the centroid x2 coordinate of this triangle -*/ + * Returns the centroid x2 coordinate of this triangle. + * @return the centroid x2 coordinate of this triangle + */ double GbTriangle3D::getX2Centroid() { - if(!this->consistent) this->calculateValues(); - return(this->x2s); + if (!this->consistent) + this->calculateValues(); + return (this->x2s); } -/* -* Returns the minimum x2 coordinate of this triangle. -* @return the minimum x2 coordinate of this triangle -*/ +/* + * Returns the minimum x2 coordinate of this triangle. + * @return the minimum x2 coordinate of this triangle + */ double GbTriangle3D::getX2Minimum() { - if(!this->consistent) this->calculateValues(); - return(this->x2min); + if (!this->consistent) + this->calculateValues(); + return (this->x2min); } /* -* Returns the maximum x2 coordinate of this triangle. -* @return the maximum x2 coordinate of this triangle -*/ + * Returns the maximum x2 coordinate of this triangle. + * @return the maximum x2 coordinate of this triangle + */ double GbTriangle3D::getX2Maximum() { - if(!this->consistent) this->calculateValues(); - return(this->x2max); + if (!this->consistent) + this->calculateValues(); + return (this->x2max); } double GbTriangle3D::getX3Centroid() { - if(!this->consistent) this->calculateValues(); - return(this->x3s); + if (!this->consistent) + this->calculateValues(); + return (this->x3s); } double GbTriangle3D::getX3Minimum() { - if(!this->consistent) this->calculateValues(); - return(this->x3min); + if (!this->consistent) + this->calculateValues(); + return (this->x3min); } double GbTriangle3D::getX3Maximum() { - if(!this->consistent) this->calculateValues(); - return(this->x3max); + if (!this->consistent) + this->calculateValues(); + return (this->x3max); } /* -* Sets the specified point. -* @param point the point -* @param index the index (must be 0, 1, or 2) -* @exception ArrayIndexOutOfBoundsException if the specified index is not valid -*/ -void GbTriangle3D::setPoint(GbPoint3D* point, int index) + * Sets the specified point. + * @param point the point + * @param index the index (must be 0, 1, or 2) + * @exception ArrayIndexOutOfBoundsException if the specified index is not valid + */ +void GbTriangle3D::setPoint(GbPoint3D *point, int index) { - if(index < 0 || index > 2) throw UbException(UB_EXARGS,"invalid index specified: "); - this->points[index] = point; - this->consistent = false; - this->calculateNormal(); + if (index < 0 || index > 2) + throw UbException(UB_EXARGS, "invalid index specified: "); + this->points[index] = point; + this->consistent = false; + this->calculateNormal(); } /* -* Returns the surface triangle set with new nodes !!! -* @returns the surface triangle set with new nodes !!! -*/ -vector<GbTriangle3D*> GbTriangle3D::getSurfaceTriangleSet() + * Returns the surface triangle set with new nodes !!! + * @returns the surface triangle set with new nodes !!! + */ +vector<GbTriangle3D *> GbTriangle3D::getSurfaceTriangleSet() { - vector<GbTriangle3D*> triangles; - - triangles.push_back(new GbTriangle3D(new GbPoint3D(getPoint1()),new GbPoint3D(getPoint2()),new GbPoint3D(getPoint3()))); + vector<GbTriangle3D *> triangles; - return triangles; -} + triangles.push_back( + new GbTriangle3D(new GbPoint3D(getPoint1()), new GbPoint3D(getPoint2()), new GbPoint3D(getPoint3()))); + return triangles; +} /* -* Returns the string representation of the triangle -* @returns the string representation of the triangle -*/ + * Returns the string representation of the triangle + * @returns the string representation of the triangle + */ string GbTriangle3D::toString() { - stringstream ss; - ss<<"GbTriangle3D[area="; - ss<<this->getArea(); - - ss<<", x1s="<<this->x1s; - ss<<", x2s="<<this->x2s; - ss<<", x3s="<<this->x3s; - ss<<", x1min="<<this->x1min; - ss<<", x1max="<<this->x1max; - ss<<", x2min="<<this->x2min; - ss<<", x2max="<<this->x2max; - ss<<", x3min="<<this->x3min; - ss<<", x3max="<<this->x3max; - ss<<", points1="<<this->points[0]->toString(); - ss<<", points2="<<this->points[1]->toString(); - ss<<", points3="<<this->points[2]->toString(); - ss<<"]"; - return((ss.str()).c_str()); + stringstream ss; + ss << "GbTriangle3D[area="; + ss << this->getArea(); + + ss << ", x1s=" << this->x1s; + ss << ", x2s=" << this->x2s; + ss << ", x3s=" << this->x3s; + ss << ", x1min=" << this->x1min; + ss << ", x1max=" << this->x1max; + ss << ", x2min=" << this->x2min; + ss << ", x2max=" << this->x2max; + ss << ", x3min=" << this->x3min; + ss << ", x3max=" << this->x3max; + ss << ", points1=" << this->points[0]->toString(); + ss << ", points2=" << this->points[1]->toString(); + ss << ", points3=" << this->points[2]->toString(); + ss << "]"; + return ((ss.str()).c_str()); } /*======================================================================*/ -double GbTriangle3D::getIntersectionRaytraceFactor(const double& x1, const double& x2, const double& x3, const double& rx1, const double& rx2, const double& rx3) +double GbTriangle3D::getIntersectionRaytraceFactor(const double &x1, const double &x2, const double &x3, + const double &rx1, const double &rx2, const double &rx3) { - //e1 = v1 - v0 - double e1x1 = this->points[1]->x1-this->points[0]->x1; - double e1x2 = this->points[1]->x2-this->points[0]->x2; - double e1x3 = this->points[1]->x3-this->points[0]->x3; - - //e2 = v2 - v0 - double e2x1 = this->points[2]->x1-this->points[0]->x1; - double e2x2 = this->points[2]->x2-this->points[0]->x2; - double e2x3 = this->points[2]->x3-this->points[0]->x3; - - //p = d x e2 - double px1 = rx2*e2x3 - rx3*e2x2; - double px2 = rx3*e2x1 - rx1*e2x3; - double px3 = rx1*e2x2 - rx2*e2x1; - - //a = e1 dot p - double a = e1x1*px1 + e1x2*px2 + e1x3*px3; - if(fabs(a)<1.E-10) return -1.0; - double f = 1.0/a; - - //s = o - v0 - double sx1 = x1 - this->points[0]->x1; - double sx2 = x2 - this->points[0]->x2; - double sx3 = x3 - this->points[0]->x3; - - //u = f * ( s dot p) - double u = f * ( sx1*px1 + sx2*px2 + sx3*px3 ); - if(u<-1.E-10 || u>1.0+1.E-10) return -1.0; - - //q = s x e1 - double qx1 = sx2*e1x3 - sx3*e1x2; - double qx2 = sx3*e1x1 - sx1*e1x3; - double qx3 = sx1*e1x2 - sx2*e1x1; - - //v = f*(e2 dot q) - double v = f * (rx1*qx1 + rx2*qx2 + rx3*qx3); - if(v<-1.E-10 || (u+v)>1.0+1.E-10) return -1.0; - - //t = f * (e2 dot q) - return f * (e2x1*qx1 + e2x2*qx2 + e2x3*qx3); + // e1 = v1 - v0 + double e1x1 = this->points[1]->x1 - this->points[0]->x1; + double e1x2 = this->points[1]->x2 - this->points[0]->x2; + double e1x3 = this->points[1]->x3 - this->points[0]->x3; + + // e2 = v2 - v0 + double e2x1 = this->points[2]->x1 - this->points[0]->x1; + double e2x2 = this->points[2]->x2 - this->points[0]->x2; + double e2x3 = this->points[2]->x3 - this->points[0]->x3; + + // p = d x e2 + double px1 = rx2 * e2x3 - rx3 * e2x2; + double px2 = rx3 * e2x1 - rx1 * e2x3; + double px3 = rx1 * e2x2 - rx2 * e2x1; + + // a = e1 dot p + double a = e1x1 * px1 + e1x2 * px2 + e1x3 * px3; + if (fabs(a) < 1.E-10) + return -1.0; + double f = 1.0 / a; + + // s = o - v0 + double sx1 = x1 - this->points[0]->x1; + double sx2 = x2 - this->points[0]->x2; + double sx3 = x3 - this->points[0]->x3; + + // u = f * ( s dot p) + double u = f * (sx1 * px1 + sx2 * px2 + sx3 * px3); + if (u < -1.E-10 || u > 1.0 + 1.E-10) + return -1.0; + + // q = s x e1 + double qx1 = sx2 * e1x3 - sx3 * e1x2; + double qx2 = sx3 * e1x1 - sx1 * e1x3; + double qx3 = sx1 * e1x2 - sx2 * e1x1; + + // v = f*(e2 dot q) + double v = f * (rx1 * qx1 + rx2 * qx2 + rx3 * qx3); + if (v < -1.E-10 || (u + v) > 1.0 + 1.E-10) + return -1.0; + + // t = f * (e2 dot q) + return f * (e2x1 * qx1 + e2x2 * qx2 + e2x3 * qx3); } /*===========================================================*/ -GbLine3D* GbTriangle3D::createClippedLine3D(GbPoint3D& point1, GbPoint3D& point2) +GbLine3D *GbTriangle3D::createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) { - GbPoint3D *result = this->calculateIntersectionPoints3D(&point1, &point2); - if(!result) return NULL; + GbPoint3D *result = this->calculateIntersectionPoints3D(&point1, &point2); + if (!result) + return NULL; - return new GbLine3D(result, new GbPoint3D(point2)); + return new GbLine3D(result, new GbPoint3D(point2)); - //return GbSystem::createClipLine3D(point1, point2, - //p1->getX1Coordinate(),p1->getX2Coordinate(),p1->getX3Coordinate(), - //p2->getX1Coordinate(),p2->getX2Coordinate(),p2->getX3Coordinate() ); + // return GbSystem::createClipLine3D(point1, point2, + // p1->getX1Coordinate(),p1->getX2Coordinate(),p1->getX3Coordinate(), + // p2->getX1Coordinate(),p2->getX2Coordinate(),p2->getX3Coordinate() ); } -//von Navodit ... +// von Navodit ... /*===========================================================*/ -GbPoint3D* GbTriangle3D::calculateIntersectionPoints3D(GbLine3D* line) +GbPoint3D *GbTriangle3D::calculateIntersectionPoints3D(GbLine3D *line) { - return this->calculateIntersectionPoints3D(line->getPoint1(), line->getPoint2()); + return this->calculateIntersectionPoints3D(line->getPoint1(), line->getPoint2()); } /*===========================================================*/ -GbPoint3D* GbTriangle3D::calculateIntersectionPoints3D(GbPoint3D* linePoint1, GbPoint3D* linePoint2) +GbPoint3D *GbTriangle3D::calculateIntersectionPoints3D(GbPoint3D *linePoint1, GbPoint3D *linePoint2) { - GbVector3D Point1(linePoint1->x1, linePoint1->x2, linePoint1->x3); - GbVector3D Point2(linePoint2->x1, linePoint2->x2, linePoint2->x3); - GbVector3D direction = Point2-Point1; - GbVector3D GbPoint3D1(this->getPoint1()->x1,this->getPoint1()->x2,this->getPoint1()->x3); - GbVector3D GbPoint3D2(this->getPoint2()->x1,this->getPoint2()->x2,this->getPoint2()->x3); - GbVector3D GbPoint3D3(this->getPoint3()->x1,this->getPoint3()->x2,this->getPoint3()->x3); - GbVector3D V2V1 = GbPoint3D2-GbPoint3D1; - GbVector3D V3V1 = GbPoint3D3-GbPoint3D1; - GbVector3D V2V1V3V1 = V2V1.Cross(V3V1); - V2V1V3V1.Normalize(); - GbVector3D Normal = V2V1V3V1; - - double d = -Normal.Dot(GbPoint3D1); - double denom = Normal.Dot(direction); - - if (UbMath::zero(denom)) return NULL; //line does not intersect the plane of the triangle ! - else - { - double mu = -1.*(d + Point1.Dot(Normal))/denom; //mu = -(d+ Normal.Point1)/denom - - // GbVector3D p1 = Point2-Point1; - // GbVector3D p2 = p1*mu; - // GbVector3D p3 = Point1+p2; - GbVector3D point = Point1 + mu*(Point2 -Point1); - - if (mu<0.0 || mu>1.0) return NULL; // Point of intersection of line and plane does not lie on the triangle - else - { - //Test whether Point lies inside the triangle or not - bool test=true; - GbVector3D a = GbPoint3D1-point; - GbVector3D b = GbPoint3D2-point; - GbVector3D c = GbPoint3D3-point; - GbVector3D ab = a.Cross(b); - GbVector3D bc = b.Cross(c); - GbVector3D ca = c.Cross(a); - GbVector3D Q1 = ab*0.5; - GbVector3D Q2 = bc*0.5; - GbVector3D Q3 = ca*0.5; - GbVector3D Q1Q2 = Q1+Q2; - GbVector3D Q = Q1Q2+Q3; - - if (UbMath::less(Q.Dot(Q1), 0.0)) test = false; - if (UbMath::less(Q.Dot(Q2), 0.0)) test = false; - if (UbMath::less(Q.Dot(Q3), 0.0)) test = false; - - if (test == true) return (new GbPoint3D(point.X1(), point.X2(), point.X3())); - else return NULL; - } - } + GbVector3D Point1(linePoint1->x1, linePoint1->x2, linePoint1->x3); + GbVector3D Point2(linePoint2->x1, linePoint2->x2, linePoint2->x3); + GbVector3D direction = Point2 - Point1; + GbVector3D GbPoint3D1(this->getPoint1()->x1, this->getPoint1()->x2, this->getPoint1()->x3); + GbVector3D GbPoint3D2(this->getPoint2()->x1, this->getPoint2()->x2, this->getPoint2()->x3); + GbVector3D GbPoint3D3(this->getPoint3()->x1, this->getPoint3()->x2, this->getPoint3()->x3); + GbVector3D V2V1 = GbPoint3D2 - GbPoint3D1; + GbVector3D V3V1 = GbPoint3D3 - GbPoint3D1; + GbVector3D V2V1V3V1 = V2V1.Cross(V3V1); + V2V1V3V1.Normalize(); + GbVector3D Normal = V2V1V3V1; + + double d = -Normal.Dot(GbPoint3D1); + double denom = Normal.Dot(direction); + + if (UbMath::zero(denom)) + return NULL; // line does not intersect the plane of the triangle ! + else { + double mu = -1. * (d + Point1.Dot(Normal)) / denom; // mu = -(d+ Normal.Point1)/denom + + // GbVector3D p1 = Point2-Point1; + // GbVector3D p2 = p1*mu; + // GbVector3D p3 = Point1+p2; + GbVector3D point = Point1 + mu * (Point2 - Point1); + + if (mu < 0.0 || mu > 1.0) + return NULL; // Point of intersection of line and plane does not lie on the triangle + else { + // Test whether Point lies inside the triangle or not + bool test = true; + GbVector3D a = GbPoint3D1 - point; + GbVector3D b = GbPoint3D2 - point; + GbVector3D c = GbPoint3D3 - point; + GbVector3D ab = a.Cross(b); + GbVector3D bc = b.Cross(c); + GbVector3D ca = c.Cross(a); + GbVector3D Q1 = ab * 0.5; + GbVector3D Q2 = bc * 0.5; + GbVector3D Q3 = ca * 0.5; + GbVector3D Q1Q2 = Q1 + Q2; + GbVector3D Q = Q1Q2 + Q3; + + if (UbMath::less(Q.Dot(Q1), 0.0)) + test = false; + if (UbMath::less(Q.Dot(Q2), 0.0)) + test = false; + if (UbMath::less(Q.Dot(Q3), 0.0)) + test = false; + + if (test == true) + return (new GbPoint3D(point.X1(), point.X2(), point.X3())); + else + return NULL; + } + } } /** -* Returns the distance between the 3D triangle and the specified 3D Point -* @param point the 3D point from whom the distance is to be calculated -* @return the distance of the specified point from the triangle -*/ -double GbTriangle3D::calculateDistanceToPoint3D(GbPoint3D *point) + * Returns the distance between the 3D triangle and the specified 3D Point + * @param point the 3D point from whom the distance is to be calculated + * @return the distance of the specified point from the triangle + */ +double GbTriangle3D::calculateDistanceToPoint3D(GbPoint3D *point) { - return this->calculateDistanceToPoint3D(point->x1, point->x2, point->x3); + return this->calculateDistanceToPoint3D(point->x1, point->x2, point->x3); } /*=======================================================================*/ -double GbTriangle3D::calculateDistanceToPoint3D(const double& x1, const double& x2, const double& x3) +double GbTriangle3D::calculateDistanceToPoint3D(const double &x1, const double &x2, const double &x3) { - // - //throw UbException(UB_EXARGS,"Ich glaub GbTriangle3D::calculateDistanceToPoint3D(...) kann man so nicht nehmen,jedenfalls nicht fuer die q's"); - cout<<"??? ch glaub GbTriangle3D::calculateDistanceToPoint3D(...) kann man so nicht nehmen,jedenfalls nicht fuer die q's"<<endl; - GbVector3D P0(x1, x2, x3); - GbVector3D P1(this->points[0]->x1, this->points[0]->x2, this->points[0]->x3); - GbVector3D P2(this->points[1]->x1, this->points[1]->x2, this->points[1]->x3); - GbVector3D P3(this->points[2]->x1, this->points[2]->x2, this->points[2]->x3); - - //Determine normal to triangle - GbVector3D Normal = (P1-P2).Cross(P1-P3); - double alpha = UbMath::ACos((P1-P0).Dot(Normal)/((P1-P0).Length()*Normal.Length())); - - double P0P0dash = (P0-P1).Length()*cos(alpha); - Normal.Normalize(); - GbVector3D Projection = Normal*(-P0P0dash); - - GbVector3D P0dash = P0+Projection; - - //Check if point P0dash lies within the triangle P1P2P3. - bool test = false; - if ( ((P1-P0).Cross(P2-P0)).Dot(Normal) > 0 ) test = true; - if ( ((P2-P0).Cross(P3-P0)).Dot(Normal) > 0 ) test = true; - if ( ((P3-P0).Cross(P1-P0)).Dot(Normal) > 0 ) test = true; - - if (test == true) return (P0-P0dash).Length(); - else - // Determine the distance of point P0 from all edges and vertices and return the minimum distance - { - double dP0P1 = (P0-P1).Length(); //Distance of Point P0 from Point P1 - double dP0P2 = (P0-P2).Length(); //Distance of Point P0 from Point P2 - double dP0P3 = (P0-P3).Length(); //Distance of Point P0 from Point P3 - - GbVector3D MP1P2 = P2-P1; //Direction vector for line P1P2 - GbVector3D MP2P3 = P3-P2; //Direction vector for line P2P3 - GbVector3D MP3P1 = P1-P3; //Direction vector for line P3P1 - - double tP1P2 = MP1P2.Dot(P0-P1) / MP1P2.Dot(MP1P2); - double tP2P3 = MP2P3.Dot(P0-P2) / MP2P3.Dot(MP2P3); - double tP3P1 = MP3P1.Dot(P0-P3) / MP3P1.Dot(MP3P1); - - double dP1P2 = (P0-(P1+(MP1P2*tP1P2))).Length(); //Distance of Point P0 from line P1P2 - double dP2P3 = (P0-(P2+(MP2P3*tP2P3))).Length(); //Distance of Point P0 from line P2P3 - double dP3P1 = (P0-(P3+(MP3P1*tP3P1))).Length(); //Distance of Point P0 from line P3P1 - - double distanceP0[6]; //Array to store all the distances from Point P0 - distanceP0[0] = dP0P1; - distanceP0[1] = dP0P2; - distanceP0[2] = dP0P3; - distanceP0[3] = dP1P2; - distanceP0[4] = dP2P3; - distanceP0[5] = dP3P1; - - double d = 0.0; - //Find the minimum distance from Point P0 - for (int i=0; i<6; i++) - { - if(distanceP0[i]<d) d = distanceP0[i]; - } - return d; - } + // + // throw UbException(UB_EXARGS,"Ich glaub GbTriangle3D::calculateDistanceToPoint3D(...) kann man so nicht + // nehmen,jedenfalls nicht fuer die q's"); + cout << "??? ch glaub GbTriangle3D::calculateDistanceToPoint3D(...) kann man so nicht nehmen,jedenfalls nicht fuer " + "die q's" + << endl; + GbVector3D P0(x1, x2, x3); + GbVector3D P1(this->points[0]->x1, this->points[0]->x2, this->points[0]->x3); + GbVector3D P2(this->points[1]->x1, this->points[1]->x2, this->points[1]->x3); + GbVector3D P3(this->points[2]->x1, this->points[2]->x2, this->points[2]->x3); + + // Determine normal to triangle + GbVector3D Normal = (P1 - P2).Cross(P1 - P3); + double alpha = UbMath::ACos((P1 - P0).Dot(Normal) / ((P1 - P0).Length() * Normal.Length())); + + double P0P0dash = (P0 - P1).Length() * cos(alpha); + Normal.Normalize(); + GbVector3D Projection = Normal * (-P0P0dash); + + GbVector3D P0dash = P0 + Projection; + + // Check if point P0dash lies within the triangle P1P2P3. + bool test = false; + if (((P1 - P0).Cross(P2 - P0)).Dot(Normal) > 0) + test = true; + if (((P2 - P0).Cross(P3 - P0)).Dot(Normal) > 0) + test = true; + if (((P3 - P0).Cross(P1 - P0)).Dot(Normal) > 0) + test = true; + + if (test == true) + return (P0 - P0dash).Length(); + else + // Determine the distance of point P0 from all edges and vertices and return the minimum distance + { + double dP0P1 = (P0 - P1).Length(); // Distance of Point P0 from Point P1 + double dP0P2 = (P0 - P2).Length(); // Distance of Point P0 from Point P2 + double dP0P3 = (P0 - P3).Length(); // Distance of Point P0 from Point P3 + + GbVector3D MP1P2 = P2 - P1; // Direction vector for line P1P2 + GbVector3D MP2P3 = P3 - P2; // Direction vector for line P2P3 + GbVector3D MP3P1 = P1 - P3; // Direction vector for line P3P1 + + double tP1P2 = MP1P2.Dot(P0 - P1) / MP1P2.Dot(MP1P2); + double tP2P3 = MP2P3.Dot(P0 - P2) / MP2P3.Dot(MP2P3); + double tP3P1 = MP3P1.Dot(P0 - P3) / MP3P1.Dot(MP3P1); + + double dP1P2 = (P0 - (P1 + (MP1P2 * tP1P2))).Length(); // Distance of Point P0 from line P1P2 + double dP2P3 = (P0 - (P2 + (MP2P3 * tP2P3))).Length(); // Distance of Point P0 from line P2P3 + double dP3P1 = (P0 - (P3 + (MP3P1 * tP3P1))).Length(); // Distance of Point P0 from line P3P1 + + double distanceP0[6]; // Array to store all the distances from Point P0 + distanceP0[0] = dP0P1; + distanceP0[1] = dP0P2; + distanceP0[2] = dP0P3; + distanceP0[3] = dP1P2; + distanceP0[4] = dP2P3; + distanceP0[5] = dP3P1; + + double d = 0.0; + // Find the minimum distance from Point P0 + for (int i = 0; i < 6; i++) { + if (distanceP0[i] < d) + d = distanceP0[i]; + } + return d; + } } /** -* Returns the normalized distance between the 3D triangle and the specified 3D Point -* copied from Benjamin A. -* @param point the 3D point from whom the distance is to be calculated -* @return the distance of the specified point from the triangle -*/ -double GbTriangle3D::calculateNormalizedDistanceToPoint3D(const double& x1, const double& y1, const double& z1, - const double& x2, const double& y2, const double& z2) + * Returns the normalized distance between the 3D triangle and the specified 3D Point + * copied from Benjamin A. + * @param point the 3D point from whom the distance is to be calculated + * @return the distance of the specified point from the triangle + */ +double GbTriangle3D::calculateNormalizedDistanceToPoint3D(const double &x1, const double &y1, const double &z1, + const double &x2, const double &y2, const double &z2) { - //face* pf + // face* pf double xa, xb, xc, ya, yb, yc, za, zb, zc; - //double xp, yp, zp; - double tt=0, xi=0, eta=0; + // double xp, yp, zp; + double tt = 0, xi = 0, eta = 0; double zaehler, nenner; double wurzel3 = sqrt(3.); - //Weltkoordinaten der Dreiecke + // Weltkoordinaten der Dreiecke xa = this->points[0]->x1; xb = this->points[1]->x1; xc = this->points[2]->x1; - + ya = this->points[0]->x2; yb = this->points[1]->x2; yc = this->points[2]->x2; @@ -521,164 +563,185 @@ double GbTriangle3D::calculateNormalizedDistanceToPoint3D(const double& x1, cons zb = this->points[1]->x3; zc = this->points[2]->x3; - //Shape-Funktionen zum Berechnen der Schnittpunkte - zaehler = - static_cast<double>(((-1.0*zc+zb)*ya+(yc-1.0*yb)*za+zc*yb-1.0*zb*yc)*x1 - +((-1.0*zb+zc)*xa+(xb-1.0*xc)*za-1.0*xb*zc+xc*zb)*y1+((-1.0*yc+yb)*xa - +(-1.0*xb+xc)*ya-1.0*xc*yb+xb*yc)*z1+((-1.0*zc+zb)*ya+(yc-1.0*yb)*za - +zc*yb-1.0*zb*yc)*x2+((-1.0*zb+zc)*xa+(xb-1.0*xc)*za-1.0*xb*zc+xc*zb)*y2 - +((-1.0*yc+yb)*xa+(-1.0*xb+xc)*ya-1.0*xc*yb+xb*yc)*z2+(2.0*zb*yc-2.0*zc*yb)*xa - +(2.0*xb*zc-2.0*xc*zb)*ya+(-2.0*xb*yc+2.0*xc*yb)*za); - nenner = - static_cast<double>((((-1.0*zc+zb)*ya+(yc-1.0*yb)*za+zc*yb-1.0*zb*yc)*x1 - +((-1.0*zb+zc)*xa+(xb-1.0*xc)*za-1.0*xb*zc+xc*zb)*y1+((-1.0*yc+yb)*xa - +(-1.0*xb+xc)*ya-1.0*xc*yb+xb*yc)*z1+((-1.0*zb+zc)*ya+(-1.0*yc+yb)*za-1.0*zc*yb+zb*yc) - *x2+((-1.0*zc+zb)*xa+(-1.0*xb+xc)*za+xb*zc-1.0*xc*zb)*y2+((yc-1.0*yb)*xa+(xb - -1.0*xc)*ya+xc*yb-1.0*xb*yc)*z2)); - if( UbMath::greater(nenner, 0.0) ) tt = zaehler/nenner; - else tt=-999.; - - zaehler = - static_cast<double>(((-2.0*zc+za+zb)*y2+(-1.0*yb-1.0*ya+2.0*yc)*z2+zc*ya - -1.0*zb*yc+zc*yb-1.0*za*yc)*x1+((-1.0*za+2.0*zc-1.0*zb)*x2+(xa-2.0*xc+xb)*z2 - -1.0*xa*zc-1.0*xb*zc+xc*za+xc*zb)*y1+((-2.0*yc+ya+yb)*x2+(-1.0*xa-1.0*xb+2.0*xc) - *y2-1.0*xc*yb+xa*yc+xb*yc-1.0*xc*ya)*z1+(zb*yc-1.0*zc*ya-1.0*zc*yb+za*yc) - *x2+(-1.0*xc*za+xb*zc+xa*zc-1.0*xc*zb)*y2+(xc*yb-1.0*xa*yc-1.0*xb*yc+xc*ya)*z2); - nenner = - static_cast<double>((((zc-1.0*zb)*ya+(yb-1.0*yc)*za+zb*yc-1.0*zc*yb)*x1 - +((zb-1.0*zc)*xa+(xc-1.0*xb)*za-1.0*xc*zb+xb*zc)*y1+((-1.0*yb+yc)*xa+(xb-1.0*xc) - *ya-1.0*xb*yc+xc*yb)*z1+((zb-1.0*zc)*ya+(-1.0*yb+yc)*za+zc*yb-1.0*zb*yc)*x2 - +((zc-1.0*zb)*xa+(xb-1.0*xc)*za-1.0*xb*zc+xc*zb)*y2+((yb-1.0*yc)*xa - +(xc-1.0*xb)*ya+xb*yc-1.0*xc*yb)*z2)); - if( UbMath::greater(nenner, 0.0) ) xi = zaehler/nenner; - else xi=-999.; - - zaehler = - static_cast<double>(((za-1.0*zb)*y2+(-1.0*ya+yb)*z2-1.0*za*yb+zb*ya)*x1+ - ((-1.0*za+zb)*x2+(xa-1.0*xb)*z2-1.0*xa*zb+xb*za)*y1+((ya-1.0*yb)*x2+(xb-1.0*xa) - *y2+xa*yb-1.0*xb*ya)*z1+(-1.0*zb*ya+za*yb)*x2+(-1.0*xb*za+xa*zb)*y2 - +(-1.0*xa*yb+xb*ya)*z2); - nenner = - static_cast<double>((((zc-1.0*zb)*ya+(yb-1.0*yc)*za+zb*yc-1.0*zc*yb)*x1 - +((zb-1.0*zc)*xa+(xc-1.0*xb)*za-1.0*xc*zb+xb*zc)*y1+((-1.0*yb+yc)*xa+(xb-1.0*xc) - *ya-1.0*xb*yc+xc*yb)*z1+((zb-1.0*zc)*ya+(-1.0*yb+yc)*za+zc*yb-1.0*zb*yc)*x2 - +((zc-1.0*zb)*xa+(xb-1.0*xc)*za-1.0*xb*zc+xc*zb)*y2+((yb-1.0*yc)*xa+(xc-1.0*xb) - *ya+xb*yc-1.0*xc*yb)*z2)); - if ( UbMath::greater(nenner, 0.0) ) eta = static_cast<double>((zaehler/nenner)*wurzel3*-1.); - else eta=-999.; - - if (tt >= -1.0-UbMath::Epsilon<double>::val() && tt <= 1.0){ - if(xi >= -1.0+eta/wurzel3-UbMath::Epsilon<double>::val() && xi <= - 1.0-eta/wurzel3+UbMath::Epsilon<double>::val()){ - if (eta >= 0-UbMath::Epsilon<double>::val() && eta <= wurzel3+UbMath::Epsilon<double>::val()){ + // Shape-Funktionen zum Berechnen der Schnittpunkte + zaehler = static_cast<double>(((-1.0 * zc + zb) * ya + (yc - 1.0 * yb) * za + zc * yb - 1.0 * zb * yc) * x1 + + ((-1.0 * zb + zc) * xa + (xb - 1.0 * xc) * za - 1.0 * xb * zc + xc * zb) * y1 + + ((-1.0 * yc + yb) * xa + (-1.0 * xb + xc) * ya - 1.0 * xc * yb + xb * yc) * z1 + + ((-1.0 * zc + zb) * ya + (yc - 1.0 * yb) * za + zc * yb - 1.0 * zb * yc) * x2 + + ((-1.0 * zb + zc) * xa + (xb - 1.0 * xc) * za - 1.0 * xb * zc + xc * zb) * y2 + + ((-1.0 * yc + yb) * xa + (-1.0 * xb + xc) * ya - 1.0 * xc * yb + xb * yc) * z2 + + (2.0 * zb * yc - 2.0 * zc * yb) * xa + (2.0 * xb * zc - 2.0 * xc * zb) * ya + + (-2.0 * xb * yc + 2.0 * xc * yb) * za); + nenner = static_cast<double>((((-1.0 * zc + zb) * ya + (yc - 1.0 * yb) * za + zc * yb - 1.0 * zb * yc) * x1 + + ((-1.0 * zb + zc) * xa + (xb - 1.0 * xc) * za - 1.0 * xb * zc + xc * zb) * y1 + + ((-1.0 * yc + yb) * xa + (-1.0 * xb + xc) * ya - 1.0 * xc * yb + xb * yc) * z1 + + ((-1.0 * zb + zc) * ya + (-1.0 * yc + yb) * za - 1.0 * zc * yb + zb * yc) * x2 + + ((-1.0 * zc + zb) * xa + (-1.0 * xb + xc) * za + xb * zc - 1.0 * xc * zb) * y2 + + ((yc - 1.0 * yb) * xa + (xb - 1.0 * xc) * ya + xc * yb - 1.0 * xb * yc) * z2)); + if (UbMath::greater(nenner, 0.0)) + tt = zaehler / nenner; + else + tt = -999.; + + zaehler = static_cast<double>(((-2.0 * zc + za + zb) * y2 + (-1.0 * yb - 1.0 * ya + 2.0 * yc) * z2 + zc * ya - + 1.0 * zb * yc + zc * yb - 1.0 * za * yc) * + x1 + + ((-1.0 * za + 2.0 * zc - 1.0 * zb) * x2 + (xa - 2.0 * xc + xb) * z2 - 1.0 * xa * zc - + 1.0 * xb * zc + xc * za + xc * zb) * + y1 + + ((-2.0 * yc + ya + yb) * x2 + (-1.0 * xa - 1.0 * xb + 2.0 * xc) * y2 - 1.0 * xc * yb + + xa * yc + xb * yc - 1.0 * xc * ya) * + z1 + + (zb * yc - 1.0 * zc * ya - 1.0 * zc * yb + za * yc) * x2 + + (-1.0 * xc * za + xb * zc + xa * zc - 1.0 * xc * zb) * y2 + + (xc * yb - 1.0 * xa * yc - 1.0 * xb * yc + xc * ya) * z2); + nenner = static_cast<double>((((zc - 1.0 * zb) * ya + (yb - 1.0 * yc) * za + zb * yc - 1.0 * zc * yb) * x1 + + ((zb - 1.0 * zc) * xa + (xc - 1.0 * xb) * za - 1.0 * xc * zb + xb * zc) * y1 + + ((-1.0 * yb + yc) * xa + (xb - 1.0 * xc) * ya - 1.0 * xb * yc + xc * yb) * z1 + + ((zb - 1.0 * zc) * ya + (-1.0 * yb + yc) * za + zc * yb - 1.0 * zb * yc) * x2 + + ((zc - 1.0 * zb) * xa + (xb - 1.0 * xc) * za - 1.0 * xb * zc + xc * zb) * y2 + + ((yb - 1.0 * yc) * xa + (xc - 1.0 * xb) * ya + xb * yc - 1.0 * xc * yb) * z2)); + if (UbMath::greater(nenner, 0.0)) + xi = zaehler / nenner; + else + xi = -999.; + + zaehler = static_cast<double>(((za - 1.0 * zb) * y2 + (-1.0 * ya + yb) * z2 - 1.0 * za * yb + zb * ya) * x1 + + ((-1.0 * za + zb) * x2 + (xa - 1.0 * xb) * z2 - 1.0 * xa * zb + xb * za) * y1 + + ((ya - 1.0 * yb) * x2 + (xb - 1.0 * xa) * y2 + xa * yb - 1.0 * xb * ya) * z1 + + (-1.0 * zb * ya + za * yb) * x2 + (-1.0 * xb * za + xa * zb) * y2 + + (-1.0 * xa * yb + xb * ya) * z2); + nenner = static_cast<double>((((zc - 1.0 * zb) * ya + (yb - 1.0 * yc) * za + zb * yc - 1.0 * zc * yb) * x1 + + ((zb - 1.0 * zc) * xa + (xc - 1.0 * xb) * za - 1.0 * xc * zb + xb * zc) * y1 + + ((-1.0 * yb + yc) * xa + (xb - 1.0 * xc) * ya - 1.0 * xb * yc + xc * yb) * z1 + + ((zb - 1.0 * zc) * ya + (-1.0 * yb + yc) * za + zc * yb - 1.0 * zb * yc) * x2 + + ((zc - 1.0 * zb) * xa + (xb - 1.0 * xc) * za - 1.0 * xb * zc + xc * zb) * y2 + + ((yb - 1.0 * yc) * xa + (xc - 1.0 * xb) * ya + xb * yc - 1.0 * xc * yb) * z2)); + if (UbMath::greater(nenner, 0.0)) + eta = static_cast<double>((zaehler / nenner) * wurzel3 * -1.); + else + eta = -999.; + + if (tt >= -1.0 - UbMath::Epsilon<double>::val() && tt <= 1.0) { + if (xi >= -1.0 + eta / wurzel3 - UbMath::Epsilon<double>::val() && + xi <= 1.0 - eta / wurzel3 + UbMath::Epsilon<double>::val()) { + if (eta >= 0 - UbMath::Epsilon<double>::val() && eta <= wurzel3 + UbMath::Epsilon<double>::val()) { /*xp = x1*(0.5-tt/2)+x2*(0.5+tt/2); yp = y1*(0.5-tt/2)+y2*(0.5+tt/2); zp = z1*(0.5-tt/2)+z2*(0.5+tt/2);*/ - return - static_cast<double>((sqrt(pow((x1*(0.5-tt/2)+x2*(0.5+tt/2))-x1,2) - +pow((y1*(0.5-tt/2)+y2*(0.5+tt/2))-y1,2)+pow((z1*(0.5-tt/2)+z2*(0.5+tt/2))-z1,2)))); - } - } + return static_cast<double>((sqrt(pow((x1 * (0.5 - tt / 2) + x2 * (0.5 + tt / 2)) - x1, 2) + + pow((y1 * (0.5 - tt / 2) + y2 * (0.5 + tt / 2)) - y1, 2) + + pow((z1 * (0.5 - tt / 2) + z2 * (0.5 + tt / 2)) - z1, 2)))); + } + } } return (-999.); } /* -* Returns true if the specified 2D point lies within (or on the border of) this 2D triangle. -* @param point the 2D point to check -* @return true if the specified 2D point lies within (or on the border of) this 2D triangle -*/ - bool GbTriangle3D::enclosesPoint2D(double x1, double x2) - { - int i=0; - //Punkt(x1,x2) liegt auf einem der Eckpunkte - if(x1==this->getPoint(0)->getX1Coordinate() && x2 == this->getPoint(0)->getX2Coordinate()) return true; - if(x1==this->getPoint(1)->getX1Coordinate() && x2 == this->getPoint(1)->getX2Coordinate()) return true; - if(x1==this->getPoint(2)->getX1Coordinate() && x2 == this->getPoint(2)->getX2Coordinate()) return true; - - //Erste Grade aus dem zu pruefenden Punkt(x,y) und einem zweiten Punkt(x+0.333,y+2.333) - GbPoint3D p1; p1.setX1(x1); p1.setX2(x2); p1.setX3(0.0); - GbPoint3D p2; p2.setX1(x1+0.333); p2.setX2(x2+3.333); p2.setX3(0.0); - //Punkte des Dreiecks auf 2D reduziert - GbPoint3D dp1; dp1.setX1(this->getPoint(0)->getX1Coordinate()); dp1.setX2(this->getPoint(0)->getX2Coordinate()); dp1.setX3(0.0); - GbPoint3D dp2; dp2.setX1(this->getPoint(1)->getX1Coordinate()); dp2.setX2(this->getPoint(1)->getX2Coordinate()); dp2.setX3(0.0); - GbPoint3D dp3; dp3.setX1(this->getPoint(2)->getX1Coordinate()); dp3.setX2(this->getPoint(2)->getX2Coordinate()); dp3.setX3(0.0); - //ueberpruefen, ob der Punkt(x,y) innerhalt der Boundingbox des Dreiecks liegt - if( x1<this->getX1Maximum() && x1>getX1Minimum() - && x2<this->getX2Maximum() && x2>getX2Minimum()) - { - GbPoint3D* dummy = NULL; - //ueberpruefen, ob der Punkt innerhalb des Dreiecks liegt - dummy = GbSystem3D::calculateIntersectionPoint3D(p1,p2,dp1,dp2); - if(dummy!=NULL) - { - if(dummy->getX1Coordinate()==p1.getX1Coordinate() && dummy->getX2Coordinate()==p1.getX2Coordinate()) - { - delete dummy; - return true; - } - else if(dummy->getX1Coordinate()>p1.getX1Coordinate()) - { - i++; - } - else - { - i--; - } - } - if(dummy) delete dummy; - - dummy = GbSystem3D::calculateIntersectionPoint3D(p1,p2,dp2,dp3); - if(dummy!=NULL) - { - if(dummy->getX1Coordinate()==p1.getX1Coordinate() && dummy->getX2Coordinate()==p1.getX2Coordinate()) - { - if(dummy) delete dummy; - return true; - } - else if(dummy->getX1Coordinate()>p1.getX1Coordinate()) - { - i++; - } - else - { - i--; - } - } - if(dummy) delete dummy; - - dummy = GbSystem3D::calculateIntersectionPoint3D(p1,p2,dp3,dp1); - if(dummy!=NULL) - { - if(dummy->getX1Coordinate()==p1.getX1Coordinate() && dummy->getX2Coordinate()==p1.getX2Coordinate()) - { - if(dummy) delete dummy; - return true; - } - else if(dummy->getX1Coordinate()>p1.getX1Coordinate()) - { - i++; - } - else - { - i--; - } - } - if(dummy) delete dummy; - } - if(i==-1) return true; - if(i==1 ) return true; - + * Returns true if the specified 2D point lies within (or on the border of) this 2D triangle. + * @param point the 2D point to check + * @return true if the specified 2D point lies within (or on the border of) this 2D triangle + */ +bool GbTriangle3D::enclosesPoint2D(double x1, double x2) +{ + int i = 0; + // Punkt(x1,x2) liegt auf einem der Eckpunkte + if (x1 == this->getPoint(0)->getX1Coordinate() && x2 == this->getPoint(0)->getX2Coordinate()) + return true; + if (x1 == this->getPoint(1)->getX1Coordinate() && x2 == this->getPoint(1)->getX2Coordinate()) + return true; + if (x1 == this->getPoint(2)->getX1Coordinate() && x2 == this->getPoint(2)->getX2Coordinate()) + return true; + + // Erste Grade aus dem zu pruefenden Punkt(x,y) und einem zweiten Punkt(x+0.333,y+2.333) + GbPoint3D p1; + p1.setX1(x1); + p1.setX2(x2); + p1.setX3(0.0); + GbPoint3D p2; + p2.setX1(x1 + 0.333); + p2.setX2(x2 + 3.333); + p2.setX3(0.0); + // Punkte des Dreiecks auf 2D reduziert + GbPoint3D dp1; + dp1.setX1(this->getPoint(0)->getX1Coordinate()); + dp1.setX2(this->getPoint(0)->getX2Coordinate()); + dp1.setX3(0.0); + GbPoint3D dp2; + dp2.setX1(this->getPoint(1)->getX1Coordinate()); + dp2.setX2(this->getPoint(1)->getX2Coordinate()); + dp2.setX3(0.0); + GbPoint3D dp3; + dp3.setX1(this->getPoint(2)->getX1Coordinate()); + dp3.setX2(this->getPoint(2)->getX2Coordinate()); + dp3.setX3(0.0); + // ueberpruefen, ob der Punkt(x,y) innerhalt der Boundingbox des Dreiecks liegt + if (x1 < this->getX1Maximum() && x1 > getX1Minimum() && x2 < this->getX2Maximum() && x2 > getX2Minimum()) { + GbPoint3D *dummy = NULL; + // ueberpruefen, ob der Punkt innerhalb des Dreiecks liegt + dummy = GbSystem3D::calculateIntersectionPoint3D(p1, p2, dp1, dp2); + if (dummy != NULL) { + if (dummy->getX1Coordinate() == p1.getX1Coordinate() && dummy->getX2Coordinate() == p1.getX2Coordinate()) { + delete dummy; + return true; + } else if (dummy->getX1Coordinate() > p1.getX1Coordinate()) { + i++; + } else { + i--; + } + } + if (dummy) + delete dummy; + + dummy = GbSystem3D::calculateIntersectionPoint3D(p1, p2, dp2, dp3); + if (dummy != NULL) { + if (dummy->getX1Coordinate() == p1.getX1Coordinate() && dummy->getX2Coordinate() == p1.getX2Coordinate()) { + if (dummy) + delete dummy; + return true; + } else if (dummy->getX1Coordinate() > p1.getX1Coordinate()) { + i++; + } else { + i--; + } + } + if (dummy) + delete dummy; + + dummy = GbSystem3D::calculateIntersectionPoint3D(p1, p2, dp3, dp1); + if (dummy != NULL) { + if (dummy->getX1Coordinate() == p1.getX1Coordinate() && dummy->getX2Coordinate() == p1.getX2Coordinate()) { + if (dummy) + delete dummy; + return true; + } else if (dummy->getX1Coordinate() > p1.getX1Coordinate()) { + i++; + } else { + i--; + } + } + if (dummy) + delete dummy; + } + if (i == -1) + return true; + if (i == 1) + return true; + return false; - } +} ///* //* Returns a new 2D polygon clipped by the specified 2D rectangle (result may be null!). //* @param rectangle the 2D rectangle //* @return a new 2D polygon clipped by the specified 2D rectangle //*/ -GbPolygon3D* GbTriangle3D::createClippedPolygon3D(GbCuboid3D* cube) +GbPolygon3D *GbTriangle3D::createClippedPolygon3D(GbCuboid3D *cube) { - return(GbSystem3D::clipPolygon3D(this->getPoints(), cube->getPoint1()->getX1Coordinate(), cube->getPoint1()->getX2Coordinate(), cube->getPoint1()->getX3Coordinate(), cube->getPoint2()->getX1Coordinate(), cube->getPoint2()->getX2Coordinate(), cube->getPoint2()->getX3Coordinate())); + return (GbSystem3D::clipPolygon3D(this->getPoints(), cube->getPoint1()->getX1Coordinate(), + cube->getPoint1()->getX2Coordinate(), cube->getPoint1()->getX3Coordinate(), + cube->getPoint2()->getX1Coordinate(), cube->getPoint2()->getX2Coordinate(), + cube->getPoint2()->getX3Coordinate())); } ///* //* Returns a new 2D polygon clipped by the specified 2D rectangle (result may be null!). @@ -686,445 +749,400 @@ GbPolygon3D* GbTriangle3D::createClippedPolygon3D(GbCuboid3D* cube) //* @param p2 the 2nd point of the rectangle //* @return a new 2D polygon clipped by the specified 2D rectangle //*/ -//public GbPolygon2D createClippedPolygon2D(GbPoint2D p1, GbPoint2D p2) +// public GbPolygon2D createClippedPolygon2D(GbPoint2D p1, GbPoint2D p2) //{ // return(GbSystem.clipPolygon2D(this.points, p1.x1, p1.x2, p2.x1, p2.x2)); //} /* -* Returns a new 2D polygon clipped by the specified 2D rectangle (result may be null!). -* @param p1x1 the 1st x1 coordinate of the rectangle -* @param p1x2 the 1st x2 coordinate of the rectangle -* @param p2x1 the 2nd x1 coordinate of the rectangle -* @param p2x2 the 2nd x2 coordinate of the rectangle -* @return a new 2D polygon clipped by the specified 2D rectangle -*/ -GbPolygon3D* GbTriangle3D::createClippedPolygon3D(const double& p1x1, const double& p1x2, const double& p1x3, const double& p2x1, const double& p2x2, const double& p2x3) + * Returns a new 2D polygon clipped by the specified 2D rectangle (result may be null!). + * @param p1x1 the 1st x1 coordinate of the rectangle + * @param p1x2 the 1st x2 coordinate of the rectangle + * @param p2x1 the 2nd x1 coordinate of the rectangle + * @param p2x2 the 2nd x2 coordinate of the rectangle + * @return a new 2D polygon clipped by the specified 2D rectangle + */ +GbPolygon3D *GbTriangle3D::createClippedPolygon3D(const double &p1x1, const double &p1x2, const double &p1x3, + const double &p2x1, const double &p2x2, const double &p2x3) { - return(GbSystem3D::clipPolygon3D(this->getPoints(), p1x1, p1x2, p1x3, p2x1, p2x2, p2x3)); + return (GbSystem3D::clipPolygon3D(this->getPoints(), p1x1, p1x2, p1x3, p2x1, p2x2, p2x3)); } /* -* Returns true if the specified 2D rectangle lies completely within this 2D triangle. -* @param rectangle the 2D rectangle to check -* @return true if the specified 2D rectangle lies completely within this 2D triangle -*/ -//bool enclosesRectangle2D(GbRectangle2D *rectangle) + * Returns true if the specified 2D rectangle lies completely within this 2D triangle. + * @param rectangle the 2D rectangle to check + * @return true if the specified 2D rectangle lies completely within this 2D triangle + */ +// bool enclosesRectangle2D(GbRectangle2D *rectangle) //{ -// GbPolygon2D p = GbSystem.clipPolygon2D(this.points, rectangle.p1.x1, rectangle.p1.x2, rectangle.p2.x1, rectangle.p2.x2); -// return(p!=null && GbSystem.equal(Math.abs(p.getArea()), rectangle.getArea())); +// GbPolygon2D p = GbSystem.clipPolygon2D(this.points, rectangle.p1.x1, rectangle.p1.x2, rectangle.p2.x1, +// rectangle.p2.x2); return(p!=null && GbSystem.equal(Math.abs(p.getArea()), rectangle.getArea())); //} /* -* Returns true if the specified 2D rectangle lies completely within this 2D triangle. -* @param p1 the 1st point of the rectangle to check -* @param p2 the 2nd point of the rectangle to check triangle -* @return true if the specified 2D rectangle lies completely within this 2D -*/ -//public boolean enclosesRectangle2D(GbPoint2D p1, GbPoint2D p2) + * Returns true if the specified 2D rectangle lies completely within this 2D triangle. + * @param p1 the 1st point of the rectangle to check + * @param p2 the 2nd point of the rectangle to check triangle + * @return true if the specified 2D rectangle lies completely within this 2D + */ +// public boolean enclosesRectangle2D(GbPoint2D p1, GbPoint2D p2) //{ // GbPolygon2D p = GbSystem.clipPolygon2D(this.points, p1.x1, p1.x2, p2.x1, p2.x2); // return(p!=null && GbSystem.equal(Math.abs(p.getArea()), Math.abs((p1.x1-p2.x1)*(p1.x2-p2.x2)))); //} /* -* Returns true if the specified 2D rectangle lies completely within this 2D triangle. -* @param p1x1 the 1st x1 coordinate of the rectangle to check -* @param p1x2 the 1st x2 coordinate of the rectangle to check -* @param p2x1 the 2nd x1 coordinate of the rectangle to check -* @param p2x2 the 2nd x2 coordinate of the rectangle to check -* @return true if the specified 2D rectangle lies completely within this 2D triangle -*/ -//public boolean enclosesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2) + * Returns true if the specified 2D rectangle lies completely within this 2D triangle. + * @param p1x1 the 1st x1 coordinate of the rectangle to check + * @param p1x2 the 1st x2 coordinate of the rectangle to check + * @param p2x1 the 2nd x1 coordinate of the rectangle to check + * @param p2x2 the 2nd x2 coordinate of the rectangle to check + * @return true if the specified 2D rectangle lies completely within this 2D triangle + */ +// public boolean enclosesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2) //{ // GbPolygon2D p = GbSystem.clipPolygon2D(this.points, p1x1, p1x2, p2x1, p2x2); // return(p!=null && GbSystem.equal(Math.abs(p.getArea()), Math.abs((p1x1-p2x1)*(p1x2-p2x2)))); //} /* -* Returns true if the specified 2D rectangle is crossed by this 2D triangle. -* @param rectangle the 2D rectangle to check -* @return true if the specified 2D rectangle is crossed by this 2D triangle -*/ -//public boolean crossesRectangle2D(GbRectangle2D rectangle) + * Returns true if the specified 2D rectangle is crossed by this 2D triangle. + * @param rectangle the 2D rectangle to check + * @return true if the specified 2D rectangle is crossed by this 2D triangle + */ +// public boolean crossesRectangle2D(GbRectangle2D rectangle) //{ -// GbPolygon2D p = GbSystem.clipPolygon2D(this.points, rectangle.p1.x1, rectangle.p1.x2, rectangle.p2.x1, rectangle.p2.x2); -// return(p!=null && GbSystem.inOpenInterval(Math.abs(p.getArea()), 0.0, rectangle.getArea())); +// GbPolygon2D p = GbSystem.clipPolygon2D(this.points, rectangle.p1.x1, rectangle.p1.x2, rectangle.p2.x1, +// rectangle.p2.x2); return(p!=null && GbSystem.inOpenInterval(Math.abs(p.getArea()), 0.0, rectangle.getArea())); //} /* -* Returns true if the specified 2D rectangle is crossed by this 2D triangle. -* @param p1 the 1st point of the rectangle to check -* @param p2 the 2nd point of the rectangle to check -* @return true if the specified 2D rectangle is crossed by this 2D triangle -*/ -//public boolean crossesRectangle2D(GbPoint2D p1, GbPoint2D p2) + * Returns true if the specified 2D rectangle is crossed by this 2D triangle. + * @param p1 the 1st point of the rectangle to check + * @param p2 the 2nd point of the rectangle to check + * @return true if the specified 2D rectangle is crossed by this 2D triangle + */ +// public boolean crossesRectangle2D(GbPoint2D p1, GbPoint2D p2) //{ // GbPolygon2D p = GbSystem.clipPolygon2D(this.points, p1.x1, p1.x2, p2.x1, p2.x2); // return(p!=null && GbSystem.inOpenInterval(Math.abs(p.getArea()), 0.0, Math.abs((p1.x1-p2.x1)*(p1.x2-p2.x2)))); //} /* -* Returns true if the specified 2D rectangle is crossed by this 2D triangle. -* @param p1x1 the 1st x1 coordinate of the rectangle to check -* @param p1x2 the 1st x2 coordinate of the rectangle to check -* @param p2x1 the 2nd x1 coordinate of the rectangle to check -* @param p2x2 the 2nd x2 coordinate of the rectangle to check -* @return true if the specified 2D rectangle is crossed by this 2D triangle -*/ -//public boolean crossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2) + * Returns true if the specified 2D rectangle is crossed by this 2D triangle. + * @param p1x1 the 1st x1 coordinate of the rectangle to check + * @param p1x2 the 1st x2 coordinate of the rectangle to check + * @param p2x1 the 2nd x1 coordinate of the rectangle to check + * @param p2x2 the 2nd x2 coordinate of the rectangle to check + * @return true if the specified 2D rectangle is crossed by this 2D triangle + */ +// public boolean crossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2) //{ // GbPolygon2D p = GbSystem.clipPolygon2D(this.points, p1x1, p1x2, p2x1, p2x2); // return(p!=null && GbSystem.inOpenInterval(Math.abs(p.getArea()), 0.0, Math.abs((p1x1-p2x1)*(p1x2-p2x2)))); //} /* -* Returns true if the specified 2D rectangle lies (at least partly) within this 2D triangle. -* @param rectangle the 2D rectangle to check -* @return true if the specified 2D rectangle lies (at least partly) within this 2D triangle -*/ -//public boolean enclosesOrCrossesRectangle2D(GbRectangle2D rectangle) + * Returns true if the specified 2D rectangle lies (at least partly) within this 2D triangle. + * @param rectangle the 2D rectangle to check + * @return true if the specified 2D rectangle lies (at least partly) within this 2D triangle + */ +// public boolean enclosesOrCrossesRectangle2D(GbRectangle2D rectangle) //{ -// GbPolygon2D p = GbSystem.clipPolygon2D(this.points, rectangle.p1.x1, rectangle.p1.x2, rectangle.p2.x1, rectangle.p2.x2); -// return(p!=null && GbSystem.greater(Math.abs(p.getArea()), 0.0)); +// GbPolygon2D p = GbSystem.clipPolygon2D(this.points, rectangle.p1.x1, rectangle.p1.x2, rectangle.p2.x1, +// rectangle.p2.x2); return(p!=null && GbSystem.greater(Math.abs(p.getArea()), 0.0)); //} /* -* Returns true if the specified 2D rectangle lies (at least partly) within this 2D triangle. -* @param p1 the 1st point of the rectangle to check -* @param p2 the 2nd point of the rectangle to check -* @return true if the specified 2D rectangle lies (at least partly) within this 2D triangle -*/ -//public boolean enclosesOrCrossesRectangle2D(GbPoint2D p1, GbPoint2D p2) + * Returns true if the specified 2D rectangle lies (at least partly) within this 2D triangle. + * @param p1 the 1st point of the rectangle to check + * @param p2 the 2nd point of the rectangle to check + * @return true if the specified 2D rectangle lies (at least partly) within this 2D triangle + */ +// public boolean enclosesOrCrossesRectangle2D(GbPoint2D p1, GbPoint2D p2) //{ // GbPolygon2D p = GbSystem.clipPolygon2D(this.points, p1.x1, p1.x2, p2.x1, p2.x2); // return(p!=null && GbSystem.greater(Math.abs(p.getArea()), 0.0)); //} /* -* Returns true if the specified 2D rectangle lies (at least partly) within this 2D triangle. -* @param p1x1 the 1st x1 coordinate of the rectangle to check -* @param p1x2 the 1st x2 coordinate of the rectangle to check -* @param p2x1 the 2nd x1 coordinate of the rectangle to check -* @param p2x2 the 2nd x2 coordinate of the rectangle to check -* @return true if the specified 2D rectangle lies (at least partly) within this 2D triangle -*/ -//public boolean enclosesOrCrossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2) + * Returns true if the specified 2D rectangle lies (at least partly) within this 2D triangle. + * @param p1x1 the 1st x1 coordinate of the rectangle to check + * @param p1x2 the 1st x2 coordinate of the rectangle to check + * @param p2x1 the 2nd x1 coordinate of the rectangle to check + * @param p2x2 the 2nd x2 coordinate of the rectangle to check + * @return true if the specified 2D rectangle lies (at least partly) within this 2D triangle + */ +// public boolean enclosesOrCrossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2) //{ // GbPolygon2D p = GbSystem.clipPolygon2D(this.points, p1x1, p1x2, p2x1, p2x2); // return(p!=null && GbSystem.greater(Math.abs(p.getArea()), 0.0)); //} /*======================================================================*/ - /*======================================================================*/ /* Private Methoden */ /* */ void GbTriangle3D::calculateValues() { - this->x1min = this->points[0]->x1; - this->x1max = this->points[0]->x1; - this->x2min = this->points[0]->x2; - this->x2max = this->points[0]->x2; - this->x3min = this->points[0]->x3; - this->x3max = this->points[0]->x3; - - if(this->points[1]->x1 < this->x1min) this->x1min = this->points[1]->x1; - if(this->points[1]->x1 > this->x1max) this->x1max = this->points[1]->x1; - if(this->points[1]->x2 < this->x2min) this->x2min = this->points[1]->x2; - if(this->points[1]->x2 > this->x2max) this->x2max = this->points[1]->x2; - if(this->points[1]->x3 < this->x3min) this->x3min = this->points[1]->x3; - if(this->points[1]->x3 > this->x3max) this->x3max = this->points[1]->x3; - - if(this->points[2]->x1 < this->x1min) this->x1min = this->points[2]->x1; - if(this->points[2]->x1 > this->x1max) this->x1max = this->points[2]->x1; - if(this->points[2]->x2 < this->x2min) this->x2min = this->points[2]->x2; - if(this->points[2]->x2 > this->x2max) this->x2max = this->points[2]->x2; - if(this->points[2]->x3 < this->x3min) this->x3min = this->points[2]->x3; - if(this->points[2]->x3 > this->x3max) this->x3max = this->points[2]->x3; - - this->x1s = (this->points[0]->x1+this->points[1]->x1+this->points[2]->x1)/3.0; - this->x2s = (this->points[0]->x2+this->points[1]->x2+this->points[2]->x2)/3.0; - this->x3s = (this->points[0]->x3+this->points[1]->x3+this->points[2]->x3)/3.0; - - GbVector3D A(points[0]->x1,points[0]->x2,points[0]->x3); - GbVector3D B(points[1]->x1,points[1]->x2,points[1]->x3); - GbVector3D C(points[2]->x1,points[2]->x2,points[2]->x3); - GbVector3D AB = B-A; - GbVector3D AC = C-A; - GbVector3D N = AB.Cross(AC); - this->area = 0.5*N.Length(); - this->consistent = true; + this->x1min = this->points[0]->x1; + this->x1max = this->points[0]->x1; + this->x2min = this->points[0]->x2; + this->x2max = this->points[0]->x2; + this->x3min = this->points[0]->x3; + this->x3max = this->points[0]->x3; + + if (this->points[1]->x1 < this->x1min) + this->x1min = this->points[1]->x1; + if (this->points[1]->x1 > this->x1max) + this->x1max = this->points[1]->x1; + if (this->points[1]->x2 < this->x2min) + this->x2min = this->points[1]->x2; + if (this->points[1]->x2 > this->x2max) + this->x2max = this->points[1]->x2; + if (this->points[1]->x3 < this->x3min) + this->x3min = this->points[1]->x3; + if (this->points[1]->x3 > this->x3max) + this->x3max = this->points[1]->x3; + + if (this->points[2]->x1 < this->x1min) + this->x1min = this->points[2]->x1; + if (this->points[2]->x1 > this->x1max) + this->x1max = this->points[2]->x1; + if (this->points[2]->x2 < this->x2min) + this->x2min = this->points[2]->x2; + if (this->points[2]->x2 > this->x2max) + this->x2max = this->points[2]->x2; + if (this->points[2]->x3 < this->x3min) + this->x3min = this->points[2]->x3; + if (this->points[2]->x3 > this->x3max) + this->x3max = this->points[2]->x3; + + this->x1s = (this->points[0]->x1 + this->points[1]->x1 + this->points[2]->x1) / 3.0; + this->x2s = (this->points[0]->x2 + this->points[1]->x2 + this->points[2]->x2) / 3.0; + this->x3s = (this->points[0]->x3 + this->points[1]->x3 + this->points[2]->x3) / 3.0; + + GbVector3D A(points[0]->x1, points[0]->x2, points[0]->x3); + GbVector3D B(points[1]->x1, points[1]->x2, points[1]->x3); + GbVector3D C(points[2]->x1, points[2]->x2, points[2]->x3); + GbVector3D AB = B - A; + GbVector3D AC = C - A; + GbVector3D N = AB.Cross(AC); + this->area = 0.5 * N.Length(); + this->consistent = true; } /*======================================================================*/ - /*======================================================================*/ GbVector3D GbTriangle3D::getNormal() { - this->calculateNormal(); - return normal; + this->calculateNormal(); + return normal; } /*======================================================================*/ void GbTriangle3D::init() { - x1s = 0.0; - x2s = 0.0; - x3s = 0.0; - x1min = 0.0; - x1max = 0.0; - x2min = 0.0; - x2max = 0.0; - area = 0.0; - consistent = false; - points.resize(3,NULL); + x1s = 0.0; + x2s = 0.0; + x3s = 0.0; + x1min = 0.0; + x1max = 0.0; + x2min = 0.0; + x2max = 0.0; + area = 0.0; + consistent = false; + points.resize(3, NULL); } /*=======================================================*/ void GbTriangle3D::calculateNormal() { - GbPoint3D*& a = points[0]; - GbPoint3D*& b = points[1]; - GbPoint3D*& c = points[2]; - normal[0] = ( c->getX3Coordinate() - a->getX3Coordinate()) * ( b->getX2Coordinate() - a->getX2Coordinate() ) - - ( b->getX3Coordinate() - a->getX3Coordinate()) * ( c->getX2Coordinate() - a->getX2Coordinate() ); - normal[1] = ( b->getX3Coordinate() - a->getX3Coordinate()) * ( c->getX1Coordinate() - a->getX1Coordinate() ) - - ( b->getX1Coordinate() - a->getX1Coordinate()) * ( c->getX3Coordinate() - a->getX3Coordinate() ); - normal[2] = ( b->getX1Coordinate() - a->getX1Coordinate()) * ( c->getX2Coordinate() - a->getX2Coordinate() ) - - ( b->getX2Coordinate() - a->getX2Coordinate()) * ( c->getX1Coordinate() - a->getX1Coordinate() ); - normal.Normalize(); + GbPoint3D *&a = points[0]; + GbPoint3D *&b = points[1]; + GbPoint3D *&c = points[2]; + normal[0] = (c->getX3Coordinate() - a->getX3Coordinate()) * (b->getX2Coordinate() - a->getX2Coordinate()) - + (b->getX3Coordinate() - a->getX3Coordinate()) * (c->getX2Coordinate() - a->getX2Coordinate()); + normal[1] = (b->getX3Coordinate() - a->getX3Coordinate()) * (c->getX1Coordinate() - a->getX1Coordinate()) - + (b->getX1Coordinate() - a->getX1Coordinate()) * (c->getX3Coordinate() - a->getX3Coordinate()); + normal[2] = (b->getX1Coordinate() - a->getX1Coordinate()) * (c->getX2Coordinate() - a->getX2Coordinate()) - + (b->getX2Coordinate() - a->getX2Coordinate()) * (c->getX1Coordinate() - a->getX1Coordinate()); + normal.Normalize(); } /*=======================================================*/ -//toDo: +// toDo: double GbTriangle3D::getDistanceFromPoint(GbVector3D punct) { - GbVector3D Point1(this->getPoint1()->getX1Coordinate(), this->getPoint1()->getX2Coordinate(), this->getPoint1()->getX3Coordinate()); - GbVector3D Point2(this->getPoint2()->getX1Coordinate(), this->getPoint2()->getX2Coordinate(), this->getPoint2()->getX3Coordinate()); - GbVector3D Point3(this->getPoint3()->getX1Coordinate(), this->getPoint3()->getX2Coordinate(), this->getPoint3()->getX3Coordinate()); - - GbVector3D kDiff = Point1 - punct; - GbVector3D kEdge0 = Point2 - Point1; - GbVector3D kEdge1 = Point3 - Point1; - double fA00 = kEdge0.SquaredLength(); - double fA01 = kEdge0.Dot(kEdge1); - double fA11 = kEdge1.SquaredLength(); - double fB0 = kDiff.Dot(kEdge0); - double fB1 = kDiff.Dot(kEdge1); - double fC = kDiff.SquaredLength(); - double fDet = fabs(fA00*fA11-fA01*fA01); - double fS = fA01*fB1-fA11*fB0; - double fT = fA01*fB0-fA00*fB1; - double fSqrDistance; - - if (fS + fT <= fDet) - { - if (fS < (double)0.0) - { - if (fT < (double)0.0) // region 4 - { - if (fB0 < (double)0.0) - { - fT = (double)0.0; - if (-fB0 >= fA00) - { - fS = (double)1.0; - fSqrDistance = fA00+((double)2.0)*fB0+fC; - } - else - { - fS = -fB0/fA00; - fSqrDistance = fB0*fS+fC; - } - } - else - { - fS = (double)0.0; - if (fB1 >= (double)0.0) - { - fT = (double)0.0; - fSqrDistance = fC; - } - else if (-fB1 >= fA11) - { - fT = (double)1.0; - fSqrDistance = fA11+((double)2.0)*fB1+fC; - } - else - { - fT = -fB1/fA11; - fSqrDistance = fB1*fT+fC; - } - } - } - else // region 3 - { - fS = (double)0.0; - if (fB1 >= (double)0.0) - { - fT = (double)0.0; - fSqrDistance = fC; - } - else if (-fB1 >= fA11) - { - fT = (double)1.0; - fSqrDistance = fA11+((double)2.0)*fB1+fC; - } - else - { - fT = -fB1/fA11; - fSqrDistance = fB1*fT+fC; - } - } - } - else if (fT < (double)0.0) // region 5 - { - fT = (double)0.0; - if (fB0 >= (double)0.0) - { - fS = (double)0.0; - fSqrDistance = fC; - } - else if (-fB0 >= fA00) - { - fS = (double)1.0; - fSqrDistance = fA00+((double)2.0)*fB0+fC; - } - else - { - fS = -fB0/fA00; - fSqrDistance = fB0*fS+fC; - } - } - else // region 0 - { - // minimum at interior point - double fInvDet = ((double)1.0)/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDistance = fS*(fA00*fS+fA01*fT+((double)2.0)*fB0) + - fT*(fA01*fS+fA11*fT+((double)2.0)*fB1)+fC; - } - } - else - { - double fTmp0, fTmp1, fNumer, fDenom; - - if (fS < (double)0.0) // region 2 - { - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if (fTmp1 > fTmp0) - { - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if (fNumer >= fDenom) - { - fS = (double)1.0; - fT = (double)0.0; - fSqrDistance = fA00+((double)2.0)*fB0+fC; - } - else - { - fS = fNumer/fDenom; - fT = (double)1.0 - fS; - fSqrDistance = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+((double)2.0)*fB1)+fC; - } - } - else - { - fS = (double)0.0; - if (fTmp1 <= (double)0.0) - { - fT = (double)1.0; - fSqrDistance = fA11+((double)2.0)*fB1+fC; - } - else if (fB1 >= (double)0.0) - { - fT = (double)0.0; - fSqrDistance = fC; - } - else - { - fT = -fB1/fA11; - fSqrDistance = fB1*fT+fC; - } - } - } - else if (fT < (double)0.0) // region 6 - { - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if (fTmp1 > fTmp0) - { - fNumer = fTmp1 - fTmp0; - fDenom = fA00-((double)2.0)*fA01+fA11; - if (fNumer >= fDenom) - { - fT = (double)1.0; - fS = (double)0.0; - fSqrDistance = fA11+((double)2.0)*fB1+fC; - } - else - { - fT = fNumer/fDenom; - fS = (double)1.0 - fT; - fSqrDistance = fS*(fA00*fS+fA01*fT+((double)2.0)*fB0) + - fT*(fA01*fS+fA11*fT+((double)2.0)*fB1)+fC; - } - } - else - { - fT = (double)0.0; - if (fTmp1 <= (double)0.0) - { - fS = (double)1.0; - fSqrDistance = fA00+((double)2.0)*fB0+fC; - } - else if (fB0 >= (double)0.0) - { - fS = (double)0.0; - fSqrDistance = fC; - } - else - { - fS = -fB0/fA00; - fSqrDistance = fB0*fS+fC; - } - } - } - else // region 1 - { - fNumer = fA11 + fB1 - fA01 - fB0; - if (fNumer <= (double)0.0) - { - fS = (double)0.0; - fT = (double)1.0; - fSqrDistance = fA11+((double)2.0)*fB1+fC; - } - else - { - fDenom = fA00-2.0f*fA01+fA11; - if (fNumer >= fDenom) - { - fS = (double)1.0; - fT = (double)0.0; - fSqrDistance = fA00+((double)2.0)*fB0+fC; - } - else - { - fS = fNumer/fDenom; - fT = (double)1.0 - fS; - fSqrDistance = fS*(fA00*fS+fA01*fT+((double)2.0)*fB0) + - fT*(fA01*fS+fA11*fT+((double)2.0)*fB1)+fC; - } - } - } - } - - // account for numerical round-off error - if (fSqrDistance < (double)0.0) - { - fSqrDistance = (double)0.0; - } -/* - m_kClosestPoint0 = punct; - m_kClosestPoint1 = m_rkTriangle.V[0] + fS*kEdge0 + fT*kEdge1; - m_afTriangleBary[1] = fS; - m_afTriangleBary[2] = fT; - m_afTriangleBary[0] = (double)1.0 - fS - fT; -*/ - return sqrt(fSqrDistance); + GbVector3D Point1(this->getPoint1()->getX1Coordinate(), this->getPoint1()->getX2Coordinate(), + this->getPoint1()->getX3Coordinate()); + GbVector3D Point2(this->getPoint2()->getX1Coordinate(), this->getPoint2()->getX2Coordinate(), + this->getPoint2()->getX3Coordinate()); + GbVector3D Point3(this->getPoint3()->getX1Coordinate(), this->getPoint3()->getX2Coordinate(), + this->getPoint3()->getX3Coordinate()); + + GbVector3D kDiff = Point1 - punct; + GbVector3D kEdge0 = Point2 - Point1; + GbVector3D kEdge1 = Point3 - Point1; + double fA00 = kEdge0.SquaredLength(); + double fA01 = kEdge0.Dot(kEdge1); + double fA11 = kEdge1.SquaredLength(); + double fB0 = kDiff.Dot(kEdge0); + double fB1 = kDiff.Dot(kEdge1); + double fC = kDiff.SquaredLength(); + double fDet = fabs(fA00 * fA11 - fA01 * fA01); + double fS = fA01 * fB1 - fA11 * fB0; + double fT = fA01 * fB0 - fA00 * fB1; + double fSqrDistance; + + if (fS + fT <= fDet) { + if (fS < (double)0.0) { + if (fT < (double)0.0) // region 4 + { + if (fB0 < (double)0.0) { + fT = (double)0.0; + if (-fB0 >= fA00) { + fS = (double)1.0; + fSqrDistance = fA00 + ((double)2.0) * fB0 + fC; + } else { + fS = -fB0 / fA00; + fSqrDistance = fB0 * fS + fC; + } + } else { + fS = (double)0.0; + if (fB1 >= (double)0.0) { + fT = (double)0.0; + fSqrDistance = fC; + } else if (-fB1 >= fA11) { + fT = (double)1.0; + fSqrDistance = fA11 + ((double)2.0) * fB1 + fC; + } else { + fT = -fB1 / fA11; + fSqrDistance = fB1 * fT + fC; + } + } + } else // region 3 + { + fS = (double)0.0; + if (fB1 >= (double)0.0) { + fT = (double)0.0; + fSqrDistance = fC; + } else if (-fB1 >= fA11) { + fT = (double)1.0; + fSqrDistance = fA11 + ((double)2.0) * fB1 + fC; + } else { + fT = -fB1 / fA11; + fSqrDistance = fB1 * fT + fC; + } + } + } else if (fT < (double)0.0) // region 5 + { + fT = (double)0.0; + if (fB0 >= (double)0.0) { + fS = (double)0.0; + fSqrDistance = fC; + } else if (-fB0 >= fA00) { + fS = (double)1.0; + fSqrDistance = fA00 + ((double)2.0) * fB0 + fC; + } else { + fS = -fB0 / fA00; + fSqrDistance = fB0 * fS + fC; + } + } else // region 0 + { + // minimum at interior point + double fInvDet = ((double)1.0) / fDet; + fS *= fInvDet; + fT *= fInvDet; + fSqrDistance = fS * (fA00 * fS + fA01 * fT + ((double)2.0) * fB0) + + fT * (fA01 * fS + fA11 * fT + ((double)2.0) * fB1) + fC; + } + } else { + double fTmp0, fTmp1, fNumer, fDenom; + + if (fS < (double)0.0) // region 2 + { + fTmp0 = fA01 + fB0; + fTmp1 = fA11 + fB1; + if (fTmp1 > fTmp0) { + fNumer = fTmp1 - fTmp0; + fDenom = fA00 - 2.0f * fA01 + fA11; + if (fNumer >= fDenom) { + fS = (double)1.0; + fT = (double)0.0; + fSqrDistance = fA00 + ((double)2.0) * fB0 + fC; + } else { + fS = fNumer / fDenom; + fT = (double)1.0 - fS; + fSqrDistance = fS * (fA00 * fS + fA01 * fT + 2.0f * fB0) + + fT * (fA01 * fS + fA11 * fT + ((double)2.0) * fB1) + fC; + } + } else { + fS = (double)0.0; + if (fTmp1 <= (double)0.0) { + fT = (double)1.0; + fSqrDistance = fA11 + ((double)2.0) * fB1 + fC; + } else if (fB1 >= (double)0.0) { + fT = (double)0.0; + fSqrDistance = fC; + } else { + fT = -fB1 / fA11; + fSqrDistance = fB1 * fT + fC; + } + } + } else if (fT < (double)0.0) // region 6 + { + fTmp0 = fA01 + fB1; + fTmp1 = fA00 + fB0; + if (fTmp1 > fTmp0) { + fNumer = fTmp1 - fTmp0; + fDenom = fA00 - ((double)2.0) * fA01 + fA11; + if (fNumer >= fDenom) { + fT = (double)1.0; + fS = (double)0.0; + fSqrDistance = fA11 + ((double)2.0) * fB1 + fC; + } else { + fT = fNumer / fDenom; + fS = (double)1.0 - fT; + fSqrDistance = fS * (fA00 * fS + fA01 * fT + ((double)2.0) * fB0) + + fT * (fA01 * fS + fA11 * fT + ((double)2.0) * fB1) + fC; + } + } else { + fT = (double)0.0; + if (fTmp1 <= (double)0.0) { + fS = (double)1.0; + fSqrDistance = fA00 + ((double)2.0) * fB0 + fC; + } else if (fB0 >= (double)0.0) { + fS = (double)0.0; + fSqrDistance = fC; + } else { + fS = -fB0 / fA00; + fSqrDistance = fB0 * fS + fC; + } + } + } else // region 1 + { + fNumer = fA11 + fB1 - fA01 - fB0; + if (fNumer <= (double)0.0) { + fS = (double)0.0; + fT = (double)1.0; + fSqrDistance = fA11 + ((double)2.0) * fB1 + fC; + } else { + fDenom = fA00 - 2.0f * fA01 + fA11; + if (fNumer >= fDenom) { + fS = (double)1.0; + fT = (double)0.0; + fSqrDistance = fA00 + ((double)2.0) * fB0 + fC; + } else { + fS = fNumer / fDenom; + fT = (double)1.0 - fS; + fSqrDistance = fS * (fA00 * fS + fA01 * fT + ((double)2.0) * fB0) + + fT * (fA01 * fS + fA11 * fT + ((double)2.0) * fB1) + fC; + } + } + } + } + + // account for numerical round-off error + if (fSqrDistance < (double)0.0) { + fSqrDistance = (double)0.0; + } + /* + m_kClosestPoint0 = punct; + m_kClosestPoint1 = m_rkTriangle.V[0] + fS*kEdge0 + fT*kEdge1; + m_afTriangleBary[1] = fS; + m_afTriangleBary[2] = fT; + m_afTriangleBary[0] = (double)1.0 - fS - fT; + */ + return sqrt(fSqrDistance); } diff --git a/src/basics/geometry3d/GbTriangle3D.h b/src/basics/geometry3d/GbTriangle3D.h index ae20245f0..a48b0828d 100644 --- a/src/basics/geometry3d/GbTriangle3D.h +++ b/src/basics/geometry3d/GbTriangle3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -36,8 +36,8 @@ #include <sstream> #include <GbObject3D.h> -#include <GbVector3D.h> #include <GbPoint3D.h> +#include <GbVector3D.h> #include <PointerDefinitions.h> @@ -46,170 +46,177 @@ class GbPolygon3D; class GbObject3DCreator; ////////////////////////////////////////////////////////////////////////// -//! +//! //! \class GbTriangle3D -//! +//! //! \brief This Class provides basic 3D triangle objects. //! \details The describing points are observed by 2D triangle objects. -//! -////////////////////////////////////////////////////////////////////////// +//! +////////////////////////////////////////////////////////////////////////// -class GbTriangle3D : public GbObject3D , public UbObserver +class GbTriangle3D : public GbObject3D, public UbObserver { public: - /*======================================================================*/ - /* Konstruktoren */ - /* */ - GbTriangle3D(); - GbTriangle3D(GbPoint3D* point1, GbPoint3D* point2, GbPoint3D* point3); - GbTriangle3D(GbTriangle3D* triangle); - ~GbTriangle3D() override; - /*======================================================================*/ - /* Methoden */ - /* */ - GbTriangle3D* clone() override; - void finalize() override - { - this->deletePoints(); - } - - GbPoint3D* getPoint1() { return this->points[0]; } - GbPoint3D* getPoint2() { return this->points[1]; } - GbPoint3D* getPoint3() { return this->points[2]; } - - GbVector3D getNormal(); - void calculateNormal(); - - void deletePoints(); - - int contains(GbPoint3D* point); - int containsEqual(GbPoint3D* point); - GbPoint3D* getPoint(const int& index); - std::vector<GbPoint3D> getPoints(); - double getArea(); - double getX1Centroid() override; - double getX1Minimum() override; - double getX1Maximum() override; - double getX2Centroid() override; - double getX2Minimum() override; - double getX2Maximum() override; - double getX3Centroid() override; - double getX3Minimum() override; - double getX3Maximum() override; - - void setInconsistent() { this->consistent = false;} - - void setPoint(GbPoint3D *point, int index); - - //bool equals(GbObject3D *object) - std::vector<GbTriangle3D*> getSurfaceTriangleSet() override; - bool isPointInGbObject3D(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/) override - { - //der einfachheit halber ... - return false; - //throw UbException(__FILE__, __LINE__, "GbTriangle3D::isPointInObject3D- not implemented"); - } - bool isPointInGbObject3D(const double& /*x1*/, const double& /*x2*/, const double& /*x3*/, bool& pointIsOnBoundary) override - { - //der einfachheit halber ... - pointIsOnBoundary = false; - return false; - //throw UbException(__FILE__, __LINE__, "GbTriangle3D::isPointInObject3D- not implemented"); - } - bool isCellInsideGbObject3D(const double& /*x11*/,const double& /*x21*/,const double& /*x31*/,const double& /*x12*/,const double& /*x22*/,const double& /*x23*/) override { return false; } - - - // get distance from a point to the triangle - //todo CHANGE... - double getDistanceFromPoint(GbVector3D punct); - - std::string toString() override; - - /*======================================================================*/ - /* Calculation */ - /* */ -// std::vector<GbPoint3D> calculateIntersectionPoints3D(GbLine3D *line); - bool hasRaytracing() override { return true; } - /*|r| must be 1! einheitsvector!!*/ - double getIntersectionRaytraceFactor(const double& x1, const double& x2, const double& x3, const double& rx1, const double& rx2, const double& rx3) override; -// bool isPointOnEdge(GbVector3D& q); - - GbPoint3D* calculateIntersectionPoints3D(GbLine3D* line); - GbPoint3D* calculateIntersectionPoints3D(GbPoint3D* linePoint1, GbPoint3D* linePoint2); - double calculateDistanceToPoint3D(GbPoint3D *point); - double calculateDistanceToPoint3D(const double& x1, const double& x2, const double& x3); - double calculateNormalizedDistanceToPoint3D(const double& x1, const double& y1, const double& z1, const double& x2, const double& y2, const double& z2); - - bool enclosesPoint2D(double x1, double x2); - GbPolygon3D* createClippedPolygon3D(GbCuboid3D* cube); - GbLine3D* createClippedLine3D (GbPoint3D& point1, GbPoint3D& point2) override; - //public GbPolygon2D createClippedPolygon2D(GbPoint2D p1, GbPoint2D p2); - GbPolygon3D* createClippedPolygon3D(const double& p1x1, const double& p1x2, const double& p1x3, const double& p2x1, const double& p2x2, const double& p2x3); - //bool enclosesRectangle2D(GbRectangle2D *rectangle); - //public boolean enclosesRectangle2D(GbPoint2D p1, GbPoint2D p2); - //public boolean enclosesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2); - //public boolean crossesRectangle2D(GbRectangle2D rectangle); - //public boolean crossesRectangle2D(GbPoint2D p1, GbPoint2D p2); - //public boolean crossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2); - //public boolean enclosesOrCrossesRectangle2D(GbRectangle2D rectangle); - //public boolean enclosesOrCrossesRectangle2D(GbPoint2D p1, GbPoint2D p2); - //public boolean enclosesOrCrossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2); - /*======================================================================*/ - /*======================================================================*/ - /* Private Methoden */ - /* */ - virtual void calculateValues(); - - - //virtuelle Methoden von UbObserver - //!! quick and dirty von sirann !! - void objectChanged(UbObservable* changedObject) override - { - GbPoint3D* point = dynamic_cast<GbPoint3D*>(changedObject); - if(!point || ( this->points[0]!=point && this->points[1]!=point && this->points[2]!=point) ) - return; - - this->consistent = false; - } - void objectWillBeDeleted(UbObservable* objectForDeletion) override - { - if(this->points[0]) - { - UbObservable* observedObj = dynamic_cast<UbObservable*>(this->points[0]); - if(objectForDeletion == observedObj) { this->points[0] = NULL; } - } - if(this->points[1]) - { - UbObservable* observedObj = dynamic_cast<UbObservable*>(this->points[1]); - if(objectForDeletion == observedObj) { this->points[1] = NULL; } - } - if(this->points[2]) - { - UbObservable* observedObj = dynamic_cast<UbObservable*>(this->points[2]); - if(objectForDeletion == observedObj) { this->points[2] = NULL; } - } - //ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo - } - using GbObject3D::isPointInGbObject3D; //Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht ausprogrammieren, welche sonst hier "ueberdeckt" waere + /*======================================================================*/ + /* Konstruktoren */ + /* */ + GbTriangle3D(); + GbTriangle3D(GbPoint3D *point1, GbPoint3D *point2, GbPoint3D *point3); + GbTriangle3D(GbTriangle3D *triangle); + ~GbTriangle3D() override; + /*======================================================================*/ + /* Methoden */ + /* */ + GbTriangle3D *clone() override; + void finalize() override { this->deletePoints(); } + + GbPoint3D *getPoint1() { return this->points[0]; } + GbPoint3D *getPoint2() { return this->points[1]; } + GbPoint3D *getPoint3() { return this->points[2]; } + + GbVector3D getNormal(); + void calculateNormal(); + + void deletePoints(); + + int contains(GbPoint3D *point); + int containsEqual(GbPoint3D *point); + GbPoint3D *getPoint(const int &index); + std::vector<GbPoint3D> getPoints(); + double getArea(); + double getX1Centroid() override; + double getX1Minimum() override; + double getX1Maximum() override; + double getX2Centroid() override; + double getX2Minimum() override; + double getX2Maximum() override; + double getX3Centroid() override; + double getX3Minimum() override; + double getX3Maximum() override; + + void setInconsistent() { this->consistent = false; } + + void setPoint(GbPoint3D *point, int index); + + // bool equals(GbObject3D *object) + std::vector<GbTriangle3D *> getSurfaceTriangleSet() override; + bool isPointInGbObject3D(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/) override + { + // der einfachheit halber ... + return false; + // throw UbException(__FILE__, __LINE__, "GbTriangle3D::isPointInObject3D- not implemented"); + } + bool isPointInGbObject3D(const double & /*x1*/, const double & /*x2*/, const double & /*x3*/, + bool &pointIsOnBoundary) override + { + // der einfachheit halber ... + pointIsOnBoundary = false; + return false; + // throw UbException(__FILE__, __LINE__, "GbTriangle3D::isPointInObject3D- not implemented"); + } + bool isCellInsideGbObject3D(const double & /*x11*/, const double & /*x21*/, const double & /*x31*/, + const double & /*x12*/, const double & /*x22*/, const double & /*x23*/) override + { + return false; + } + + // get distance from a point to the triangle + // todo CHANGE... + double getDistanceFromPoint(GbVector3D punct); + + std::string toString() override; + + /*======================================================================*/ + /* Calculation */ + /* */ + // std::vector<GbPoint3D> calculateIntersectionPoints3D(GbLine3D *line); + bool hasRaytracing() override { return true; } + /*|r| must be 1! einheitsvector!!*/ + double getIntersectionRaytraceFactor(const double &x1, const double &x2, const double &x3, const double &rx1, + const double &rx2, const double &rx3) override; + // bool isPointOnEdge(GbVector3D& q); + + GbPoint3D *calculateIntersectionPoints3D(GbLine3D *line); + GbPoint3D *calculateIntersectionPoints3D(GbPoint3D *linePoint1, GbPoint3D *linePoint2); + double calculateDistanceToPoint3D(GbPoint3D *point); + double calculateDistanceToPoint3D(const double &x1, const double &x2, const double &x3); + double calculateNormalizedDistanceToPoint3D(const double &x1, const double &y1, const double &z1, const double &x2, + const double &y2, const double &z2); + + bool enclosesPoint2D(double x1, double x2); + GbPolygon3D *createClippedPolygon3D(GbCuboid3D *cube); + GbLine3D *createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) override; + // public GbPolygon2D createClippedPolygon2D(GbPoint2D p1, GbPoint2D p2); + GbPolygon3D *createClippedPolygon3D(const double &p1x1, const double &p1x2, const double &p1x3, const double &p2x1, + const double &p2x2, const double &p2x3); + // bool enclosesRectangle2D(GbRectangle2D *rectangle); + // public boolean enclosesRectangle2D(GbPoint2D p1, GbPoint2D p2); + // public boolean enclosesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2); + // public boolean crossesRectangle2D(GbRectangle2D rectangle); + // public boolean crossesRectangle2D(GbPoint2D p1, GbPoint2D p2); + // public boolean crossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2); + // public boolean enclosesOrCrossesRectangle2D(GbRectangle2D rectangle); + // public boolean enclosesOrCrossesRectangle2D(GbPoint2D p1, GbPoint2D p2); + // public boolean enclosesOrCrossesRectangle2D(double p1x1, double p1x2, double p2x1, double p2x2); + /*======================================================================*/ + /*======================================================================*/ + /* Private Methoden */ + /* */ + virtual void calculateValues(); + + // virtuelle Methoden von UbObserver + //!! quick and dirty von sirann !! + void objectChanged(UbObservable *changedObject) override + { + GbPoint3D *point = dynamic_cast<GbPoint3D *>(changedObject); + if (!point || (this->points[0] != point && this->points[1] != point && this->points[2] != point)) + return; + + this->consistent = false; + } + void objectWillBeDeleted(UbObservable *objectForDeletion) override + { + if (this->points[0]) { + UbObservable *observedObj = dynamic_cast<UbObservable *>(this->points[0]); + if (objectForDeletion == observedObj) { + this->points[0] = NULL; + } + } + if (this->points[1]) { + UbObservable *observedObj = dynamic_cast<UbObservable *>(this->points[1]); + if (objectForDeletion == observedObj) { + this->points[1] = NULL; + } + } + if (this->points[2]) { + UbObservable *observedObj = dynamic_cast<UbObservable *>(this->points[2]); + if (objectForDeletion == observedObj) { + this->points[2] = NULL; + } + } + // ACHTUNG: eigentlich muessten in allen methoden von GbLine if abfragen fuer NULL pointer hin... toDo + } + using GbObject3D::isPointInGbObject3D; // Grund: dadurch muss man hier isPointInGbObject3D(GbPoint3D*) nicht + // ausprogrammieren, welche sonst hier "ueberdeckt" waere protected: - bool consistent; - double x1s; - double x2s; - double x3s; - double x1min; - double x1max; - double x2min; - double x2max; - double x3min; - double x3max; - double area; - - GbVector3D normal; - std::vector<GbPoint3D*> points; - + bool consistent; + double x1s; + double x2s; + double x3s; + double x1min; + double x1max; + double x2min; + double x2max; + double x3min; + double x3max; + double area; + + GbVector3D normal; + std::vector<GbPoint3D *> points; + private: - void init(); + void init(); }; /*=========================================================================*/ diff --git a/src/basics/geometry3d/GbVector3D.cpp b/src/basics/geometry3d/GbVector3D.cpp index e763e425a..0c666a875 100644 --- a/src/basics/geometry3d/GbVector3D.cpp +++ b/src/basics/geometry3d/GbVector3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -30,649 +30,513 @@ //! \ingroup geometry3d //! \author Soeren Freudiger, Sebastian Geller //======================================================================================= -#include <GbVector3D.h> #include <GbPoint3D.h> +#include <GbVector3D.h> -#include <basics/utilities/UbMath.h> #include <basics/utilities/UbInfinity.h> +#include <basics/utilities/UbMath.h> using namespace std; - -const GbVector3D GbVector3D::ZERO(0.0,0.0,0.0); -const GbVector3D GbVector3D::UNIT_X1(1.0,0.0,0.0); -const GbVector3D GbVector3D::UNIT_X2(0.0,1.0,0.0); -const GbVector3D GbVector3D::UNIT_X3(0.0,0.0,1.0); +const GbVector3D GbVector3D::ZERO(0.0, 0.0, 0.0); +const GbVector3D GbVector3D::UNIT_X1(1.0, 0.0, 0.0); +const GbVector3D GbVector3D::UNIT_X2(0.0, 1.0, 0.0); +const GbVector3D GbVector3D::UNIT_X3(0.0, 0.0, 1.0); //---------------------------------------------------------------------------- -GbVector3D::GbVector3D () -{ - m_afTuple[0] = 0.0; - m_afTuple[1] = 0.0; - m_afTuple[2] = 0.0; +GbVector3D::GbVector3D() +{ + m_afTuple[0] = 0.0; + m_afTuple[1] = 0.0; + m_afTuple[2] = 0.0; } //---------------------------------------------------------------------------- -GbVector3D::GbVector3D (const double& fX, const double& fY, const double& fZ) +GbVector3D::GbVector3D(const double &fX, const double &fY, const double &fZ) { - m_afTuple[0] = fX; - m_afTuple[1] = fY; - m_afTuple[2] = fZ; + m_afTuple[0] = fX; + m_afTuple[1] = fY; + m_afTuple[2] = fZ; } //---------------------------------------------------------------------------- -GbVector3D::GbVector3D (const GbVector3D& rkV) +GbVector3D::GbVector3D(const GbVector3D &rkV) { - m_afTuple[0] = rkV.m_afTuple[0]; - m_afTuple[1] = rkV.m_afTuple[1]; - m_afTuple[2] = rkV.m_afTuple[2]; + m_afTuple[0] = rkV.m_afTuple[0]; + m_afTuple[1] = rkV.m_afTuple[1]; + m_afTuple[2] = rkV.m_afTuple[2]; } //---------------------------------------------------------------------------- -GbVector3D::GbVector3D (const GbPoint3D& point) +GbVector3D::GbVector3D(const GbPoint3D &point) { - m_afTuple[0] = point.x1; - m_afTuple[1] = point.x2; - m_afTuple[2] = point.x3; + m_afTuple[0] = point.x1; + m_afTuple[1] = point.x2; + m_afTuple[2] = point.x3; } //---------------------------------------------------------------------------- string GbVector3D::toString() { - std::stringstream ss; - ss<< "GbVector3D["<<m_afTuple[0]<<","<<m_afTuple[1]<<","<<m_afTuple[2]<<"]"; - ss<<endl; - return((ss.str()).c_str()); + std::stringstream ss; + ss << "GbVector3D[" << m_afTuple[0] << "," << m_afTuple[1] << "," << m_afTuple[2] << "]"; + ss << endl; + return ((ss.str()).c_str()); } //---------------------------------------------------------------------------- -GbVector3D::operator const double* () const -{ - return m_afTuple; -} +GbVector3D::operator const double *() const { return m_afTuple; } //---------------------------------------------------------------------------- -GbVector3D::operator double* () -{ - return m_afTuple; -} +GbVector3D::operator double *() { return m_afTuple; } //---------------------------------------------------------------------------- -double GbVector3D::operator[] (int i) const +double GbVector3D::operator[](int i) const { - assert( 0 <= i && i <= 2 ); - if ( i < 0 ) - i = 0; - else if ( i > 2 ) - i = 2; + assert(0 <= i && i <= 2); + if (i < 0) + i = 0; + else if (i > 2) + i = 2; - return m_afTuple[i]; + return m_afTuple[i]; } //---------------------------------------------------------------------------- -double& GbVector3D::operator[] (int i) +double &GbVector3D::operator[](int i) { - assert( 0 <= i && i <= 2 ); - if ( i < 0 ) - i = 0; - else if ( i > 2 ) - i = 2; + assert(0 <= i && i <= 2); + if (i < 0) + i = 0; + else if (i > 2) + i = 2; - return m_afTuple[i]; + return m_afTuple[i]; } //---------------------------------------------------------------------------- -double GbVector3D::X1 () const -{ - return m_afTuple[0]; -} +double GbVector3D::X1() const { return m_afTuple[0]; } //---------------------------------------------------------------------------- -double& GbVector3D::X1 () -{ - return m_afTuple[0]; -} +double &GbVector3D::X1() { return m_afTuple[0]; } //---------------------------------------------------------------------------- -double GbVector3D::X2 () const -{ - return m_afTuple[1]; -} +double GbVector3D::X2() const { return m_afTuple[1]; } //---------------------------------------------------------------------------- -double& GbVector3D::X2 () -{ - return m_afTuple[1]; -} +double &GbVector3D::X2() { return m_afTuple[1]; } //---------------------------------------------------------------------------- -double GbVector3D::X3 () const -{ - return m_afTuple[2]; -} +double GbVector3D::X3() const { return m_afTuple[2]; } //---------------------------------------------------------------------------- -double& GbVector3D::X3 () -{ - return m_afTuple[2]; -} +double &GbVector3D::X3() { return m_afTuple[2]; } //---------------------------------------------------------------------------- -GbVector3D& GbVector3D::operator= (const GbVector3D& rkV) +GbVector3D &GbVector3D::operator=(const GbVector3D &rkV) { - if(this == &rkV) + if (this == &rkV) return *this; m_afTuple[0] = rkV.m_afTuple[0]; - m_afTuple[1] = rkV.m_afTuple[1]; - m_afTuple[2] = rkV.m_afTuple[2]; - return *this; + m_afTuple[1] = rkV.m_afTuple[1]; + m_afTuple[2] = rkV.m_afTuple[2]; + return *this; } //---------------------------------------------------------------------------- -int GbVector3D::CompareArrays (const GbVector3D& rkV) const +int GbVector3D::CompareArrays(const GbVector3D &rkV) const { - return memcmp(m_afTuple,rkV.m_afTuple,3*sizeof(double)); + return memcmp(m_afTuple, rkV.m_afTuple, 3 * sizeof(double)); } //---------------------------------------------------------------------------- -bool GbVector3D::operator== (const GbVector3D& rkV) const -{ - return CompareArrays(rkV) == 0; -} +bool GbVector3D::operator==(const GbVector3D &rkV) const { return CompareArrays(rkV) == 0; } //---------------------------------------------------------------------------- -bool GbVector3D::operator!= (const GbVector3D& rkV) const -{ - return CompareArrays(rkV) != 0; -} +bool GbVector3D::operator!=(const GbVector3D &rkV) const { return CompareArrays(rkV) != 0; } //---------------------------------------------------------------------------- -bool GbVector3D::operator< (const GbVector3D& rkV) const -{ - return CompareArrays(rkV) < 0; -} +bool GbVector3D::operator<(const GbVector3D &rkV) const { return CompareArrays(rkV) < 0; } //---------------------------------------------------------------------------- -bool GbVector3D::operator<= (const GbVector3D& rkV) const -{ - return CompareArrays(rkV) <= 0; -} +bool GbVector3D::operator<=(const GbVector3D &rkV) const { return CompareArrays(rkV) <= 0; } //---------------------------------------------------------------------------- -bool GbVector3D::operator> (const GbVector3D& rkV) const -{ - return CompareArrays(rkV) > 0; -} +bool GbVector3D::operator>(const GbVector3D &rkV) const { return CompareArrays(rkV) > 0; } //---------------------------------------------------------------------------- -bool GbVector3D::operator>= (const GbVector3D& rkV) const -{ - return CompareArrays(rkV) >= 0; -} +bool GbVector3D::operator>=(const GbVector3D &rkV) const { return CompareArrays(rkV) >= 0; } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::operator+ (const GbVector3D& rkV) const +GbVector3D GbVector3D::operator+(const GbVector3D &rkV) const { - return GbVector3D( - m_afTuple[0]+rkV.m_afTuple[0], - m_afTuple[1]+rkV.m_afTuple[1], - m_afTuple[2]+rkV.m_afTuple[2]); + return GbVector3D(m_afTuple[0] + rkV.m_afTuple[0], m_afTuple[1] + rkV.m_afTuple[1], + m_afTuple[2] + rkV.m_afTuple[2]); } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::Add(GbVector3D& vector) +GbVector3D GbVector3D::Add(GbVector3D &vector) { - return GbVector3D( - m_afTuple[0]+vector.m_afTuple[0], - m_afTuple[1]+vector.m_afTuple[1], - m_afTuple[2]+vector.m_afTuple[2]); + return GbVector3D(m_afTuple[0] + vector.m_afTuple[0], m_afTuple[1] + vector.m_afTuple[1], + m_afTuple[2] + vector.m_afTuple[2]); } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::operator- (const GbVector3D& rkV) const +GbVector3D GbVector3D::operator-(const GbVector3D &rkV) const { - return GbVector3D( - m_afTuple[0]-rkV.m_afTuple[0], - m_afTuple[1]-rkV.m_afTuple[1], - m_afTuple[2]-rkV.m_afTuple[2]); + return GbVector3D(m_afTuple[0] - rkV.m_afTuple[0], m_afTuple[1] - rkV.m_afTuple[1], + m_afTuple[2] - rkV.m_afTuple[2]); } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::Subtract(GbVector3D& vector) +GbVector3D GbVector3D::Subtract(GbVector3D &vector) { - return GbVector3D( - m_afTuple[0]-vector.m_afTuple[0], - m_afTuple[1]-vector.m_afTuple[1], - m_afTuple[2]-vector.m_afTuple[2]); + return GbVector3D(m_afTuple[0] - vector.m_afTuple[0], m_afTuple[1] - vector.m_afTuple[1], + m_afTuple[2] - vector.m_afTuple[2]); } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::operator* (const double& fScalar) const +GbVector3D GbVector3D::operator*(const double &fScalar) const { - return GbVector3D( fScalar*m_afTuple[0], - fScalar*m_afTuple[1], - fScalar*m_afTuple[2]); + return GbVector3D(fScalar * m_afTuple[0], fScalar * m_afTuple[1], fScalar * m_afTuple[2]); } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::operator/ (const double& fScalar) const +GbVector3D GbVector3D::operator/(const double &fScalar) const { - GbVector3D kQuot; + GbVector3D kQuot; - if ( fScalar != 0.0 ) - { - double fInvScalar = 1.0/fScalar; - kQuot.m_afTuple[0] = fInvScalar*m_afTuple[0]; - kQuot.m_afTuple[1] = fInvScalar*m_afTuple[1]; - kQuot.m_afTuple[2] = fInvScalar*m_afTuple[2]; - } - else - { - kQuot.m_afTuple[0] = Ub::inf; - kQuot.m_afTuple[1] = Ub::inf; - kQuot.m_afTuple[2] = Ub::inf; - } + if (fScalar != 0.0) { + double fInvScalar = 1.0 / fScalar; + kQuot.m_afTuple[0] = fInvScalar * m_afTuple[0]; + kQuot.m_afTuple[1] = fInvScalar * m_afTuple[1]; + kQuot.m_afTuple[2] = fInvScalar * m_afTuple[2]; + } else { + kQuot.m_afTuple[0] = Ub::inf; + kQuot.m_afTuple[1] = Ub::inf; + kQuot.m_afTuple[2] = Ub::inf; + } - return kQuot; + return kQuot; } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::operator- () const -{ - return GbVector3D( - -m_afTuple[0], - -m_afTuple[1], - -m_afTuple[2]); -} +GbVector3D GbVector3D::operator-() const { return GbVector3D(-m_afTuple[0], -m_afTuple[1], -m_afTuple[2]); } //---------------------------------------------------------------------------- -GbVector3D operator* (const double& fScalar, const GbVector3D& rkV) +GbVector3D operator*(const double &fScalar, const GbVector3D &rkV) { - return GbVector3D( - fScalar*rkV[0], - fScalar*rkV[1], - fScalar*rkV[2]); + return GbVector3D(fScalar * rkV[0], fScalar * rkV[1], fScalar * rkV[2]); } //---------------------------------------------------------------------------- -GbVector3D& GbVector3D::operator+= (const GbVector3D& rkV) +GbVector3D &GbVector3D::operator+=(const GbVector3D &rkV) { - m_afTuple[0] += rkV.m_afTuple[0]; - m_afTuple[1] += rkV.m_afTuple[1]; - m_afTuple[2] += rkV.m_afTuple[2]; - return *this; + m_afTuple[0] += rkV.m_afTuple[0]; + m_afTuple[1] += rkV.m_afTuple[1]; + m_afTuple[2] += rkV.m_afTuple[2]; + return *this; } //---------------------------------------------------------------------------- -GbVector3D& GbVector3D::operator-= (const GbVector3D& rkV) +GbVector3D &GbVector3D::operator-=(const GbVector3D &rkV) { - m_afTuple[0] -= rkV.m_afTuple[0]; - m_afTuple[1] -= rkV.m_afTuple[1]; - m_afTuple[2] -= rkV.m_afTuple[2]; - return *this; + m_afTuple[0] -= rkV.m_afTuple[0]; + m_afTuple[1] -= rkV.m_afTuple[1]; + m_afTuple[2] -= rkV.m_afTuple[2]; + return *this; } //---------------------------------------------------------------------------- -GbVector3D& GbVector3D::operator*= (const double& fScalar) +GbVector3D &GbVector3D::operator*=(const double &fScalar) { - m_afTuple[0] *= fScalar; - m_afTuple[1] *= fScalar; - m_afTuple[2] *= fScalar; - return *this; + m_afTuple[0] *= fScalar; + m_afTuple[1] *= fScalar; + m_afTuple[2] *= fScalar; + return *this; } //---------------------------------------------------------------------------- -GbVector3D& GbVector3D::operator/= (const double& fScalar) +GbVector3D &GbVector3D::operator/=(const double &fScalar) { - if ( fScalar != (double)0.0 ) - { - double fInvScalar = ((double)1.0)/fScalar; - m_afTuple[0] *= fInvScalar; - m_afTuple[1] *= fInvScalar; - m_afTuple[2] *= fInvScalar; - } - else - { - m_afTuple[0] = Ub::inf; - m_afTuple[1] = Ub::inf; - m_afTuple[2] = Ub::inf; - } + if (fScalar != (double)0.0) { + double fInvScalar = ((double)1.0) / fScalar; + m_afTuple[0] *= fInvScalar; + m_afTuple[1] *= fInvScalar; + m_afTuple[2] *= fInvScalar; + } else { + m_afTuple[0] = Ub::inf; + m_afTuple[1] = Ub::inf; + m_afTuple[2] = Ub::inf; + } - return *this; + return *this; } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::Scale(const double& x) +GbVector3D GbVector3D::Scale(const double &x) { - GbVector3D PointA(0.0,0.0,0.0); - PointA.m_afTuple[0] = x * m_afTuple[0]; - PointA.m_afTuple[1] = x * m_afTuple[1]; - PointA.m_afTuple[2] = x * m_afTuple[2]; - return PointA; + GbVector3D PointA(0.0, 0.0, 0.0); + PointA.m_afTuple[0] = x * m_afTuple[0]; + PointA.m_afTuple[1] = x * m_afTuple[1]; + PointA.m_afTuple[2] = x * m_afTuple[2]; + return PointA; } //---------------------------------------------------------------------------- -double GbVector3D::Length () const +double GbVector3D::Length() const { - return std::sqrt( - m_afTuple[0]*m_afTuple[0] + - m_afTuple[1]*m_afTuple[1] + - m_afTuple[2]*m_afTuple[2]); + return std::sqrt(m_afTuple[0] * m_afTuple[0] + m_afTuple[1] * m_afTuple[1] + m_afTuple[2] * m_afTuple[2]); } //---------------------------------------------------------------------------- -double GbVector3D::SquaredLength () const +double GbVector3D::SquaredLength() const { - return - m_afTuple[0]*m_afTuple[0] + - m_afTuple[1]*m_afTuple[1] + - m_afTuple[2]*m_afTuple[2]; + return m_afTuple[0] * m_afTuple[0] + m_afTuple[1] * m_afTuple[1] + m_afTuple[2] * m_afTuple[2]; } //---------------------------------------------------------------------------- -double GbVector3D::Dot (const GbVector3D& rkV) const +double GbVector3D::Dot(const GbVector3D &rkV) const { - return - m_afTuple[0]*rkV.m_afTuple[0] + - m_afTuple[1]*rkV.m_afTuple[1] + - m_afTuple[2]*rkV.m_afTuple[2]; + return m_afTuple[0] * rkV.m_afTuple[0] + m_afTuple[1] * rkV.m_afTuple[1] + m_afTuple[2] * rkV.m_afTuple[2]; } //---------------------------------------------------------------------------- -double GbVector3D::Normalize () +double GbVector3D::Normalize() { - double fLength = Length(); + double fLength = Length(); - if ( fLength > UbMath::Epsilon<double>::val() ) - { - double fInvLength = ((double)1.0)/fLength; - m_afTuple[0] *= fInvLength; - m_afTuple[1] *= fInvLength; - m_afTuple[2] *= fInvLength; - } - else - { - fLength = 0.0; - m_afTuple[0] = 0.0; - m_afTuple[1] = 0.0; - m_afTuple[2] = 0.0; - } + if (fLength > UbMath::Epsilon<double>::val()) { + double fInvLength = ((double)1.0) / fLength; + m_afTuple[0] *= fInvLength; + m_afTuple[1] *= fInvLength; + m_afTuple[2] *= fInvLength; + } else { + fLength = 0.0; + m_afTuple[0] = 0.0; + m_afTuple[1] = 0.0; + m_afTuple[2] = 0.0; + } - return fLength; + return fLength; } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::Cross (const GbVector3D& rkV) const +GbVector3D GbVector3D::Cross(const GbVector3D &rkV) const { - return GbVector3D( - m_afTuple[1]*rkV.m_afTuple[2] - m_afTuple[2]*rkV.m_afTuple[1], - m_afTuple[2]*rkV.m_afTuple[0] - m_afTuple[0]*rkV.m_afTuple[2], - m_afTuple[0]*rkV.m_afTuple[1] - m_afTuple[1]*rkV.m_afTuple[0]); + return GbVector3D(m_afTuple[1] * rkV.m_afTuple[2] - m_afTuple[2] * rkV.m_afTuple[1], + m_afTuple[2] * rkV.m_afTuple[0] - m_afTuple[0] * rkV.m_afTuple[2], + m_afTuple[0] * rkV.m_afTuple[1] - m_afTuple[1] * rkV.m_afTuple[0]); } //---------------------------------------------------------------------------- -GbVector3D GbVector3D::UnitCross (const GbVector3D& rkV) const +GbVector3D GbVector3D::UnitCross(const GbVector3D &rkV) const { - GbVector3D kCross( - m_afTuple[1]*rkV.m_afTuple[2] - m_afTuple[2]*rkV.m_afTuple[1], - m_afTuple[2]*rkV.m_afTuple[0] - m_afTuple[0]*rkV.m_afTuple[2], - m_afTuple[0]*rkV.m_afTuple[1] - m_afTuple[1]*rkV.m_afTuple[0]); - kCross.Normalize(); - return kCross; + GbVector3D kCross(m_afTuple[1] * rkV.m_afTuple[2] - m_afTuple[2] * rkV.m_afTuple[1], + m_afTuple[2] * rkV.m_afTuple[0] - m_afTuple[0] * rkV.m_afTuple[2], + m_afTuple[0] * rkV.m_afTuple[1] - m_afTuple[1] * rkV.m_afTuple[0]); + kCross.Normalize(); + return kCross; } //---------------------------------------------------------------------------- -void GbVector3D::GetBarycentrics (const GbVector3D& rkV0, - const GbVector3D& rkV1, const GbVector3D& rkV2, - const GbVector3D& rkV3, double afBary[4]) const +void GbVector3D::GetBarycentrics(const GbVector3D &rkV0, const GbVector3D &rkV1, const GbVector3D &rkV2, + const GbVector3D &rkV3, double afBary[4]) const { - // compute the vectors relative to V3 of the tetrahedron - GbVector3D akDiff[4] = - { - rkV0 - rkV3, - rkV1 - rkV3, - rkV2 - rkV3, - *this - rkV3 - }; - - // If the vertices have large magnitude, the linear system of - // equations for computing barycentric coordinates can be - // ill-conditioned. To avoid this, uniformly scale the tetrahedron - // edges to be of order 1. The scaling of all differences does not - // change the barycentric coordinates. - double fMax = (double)0.0; - int i; - for (i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - double fValue = std::fabs(akDiff[i][j]); - if ( fValue > fMax ) - fMax = fValue; - } - } + // compute the vectors relative to V3 of the tetrahedron + GbVector3D akDiff[4] = { rkV0 - rkV3, rkV1 - rkV3, rkV2 - rkV3, *this - rkV3 }; - // scale down only large data - if ( fMax > (double)1.0 ) - { - double fInvMax = ((double)1.0)/fMax; - for (i = 0; i < 4; i++) - akDiff[i] *= fInvMax; - } + // If the vertices have large magnitude, the linear system of + // equations for computing barycentric coordinates can be + // ill-conditioned. To avoid this, uniformly scale the tetrahedron + // edges to be of order 1. The scaling of all differences does not + // change the barycentric coordinates. + double fMax = (double)0.0; + int i; + for (i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + double fValue = std::fabs(akDiff[i][j]); + if (fValue > fMax) + fMax = fValue; + } + } - double fDet = akDiff[0].Dot(akDiff[1].Cross(akDiff[2])); - GbVector3D kE1cE2 = akDiff[1].Cross(akDiff[2]); - GbVector3D kE2cE0 = akDiff[2].Cross(akDiff[0]); - GbVector3D kE0cE1 = akDiff[0].Cross(akDiff[1]); - if ( std::fabs(fDet) > UbMath::Epsilon<double>::val() ) - { - double fInvDet = ((double)1.0)/fDet; - afBary[0] = akDiff[3].Dot(kE1cE2)*fInvDet; - afBary[1] = akDiff[3].Dot(kE2cE0)*fInvDet; - afBary[2] = akDiff[3].Dot(kE0cE1)*fInvDet; - afBary[3] = (double)1.0 - afBary[0] - afBary[1] - afBary[2]; - } - else - { - // The tetrahedron is potentially flat. Determine the face of - // maximum area and compute barycentric coordinates with respect - // to that face. - GbVector3D kE02 = rkV0 - rkV2; - GbVector3D kE12 = rkV1 - rkV2; - GbVector3D kE02cE12 = kE02.Cross(kE12); - double fMaxSqrArea = kE02cE12.SquaredLength(); - int iMaxIndex = 3; - double fSqrArea = kE0cE1.SquaredLength(); - if ( fSqrArea > fMaxSqrArea ) - { - iMaxIndex = 0; - fMaxSqrArea = fSqrArea; - } - fSqrArea = kE1cE2.SquaredLength(); - if ( fSqrArea > fMaxSqrArea ) - { - iMaxIndex = 1; - fMaxSqrArea = fSqrArea; - } - fSqrArea = kE2cE0.SquaredLength(); - if ( fSqrArea > fMaxSqrArea ) - { - iMaxIndex = 2; - fMaxSqrArea = fSqrArea; - } + // scale down only large data + if (fMax > (double)1.0) { + double fInvMax = ((double)1.0) / fMax; + for (i = 0; i < 4; i++) + akDiff[i] *= fInvMax; + } - if ( fMaxSqrArea > UbMath::Epsilon<double>::val() ) - { - double fInvSqrArea = ((double)1.0)/fMaxSqrArea; - GbVector3D kTmp; - if ( iMaxIndex == 0 ) - { - kTmp = akDiff[3].Cross(akDiff[1]); - afBary[0] = kE0cE1.Dot(kTmp)*fInvSqrArea; - kTmp = akDiff[0].Cross(akDiff[3]); - afBary[1] = kE0cE1.Dot(kTmp)*fInvSqrArea; - afBary[2] = (double)0.0; - afBary[3] = (double)1.0 - afBary[0] - afBary[1]; - } - else if ( iMaxIndex == 1 ) - { - afBary[0] = (double)0.0; - kTmp = akDiff[3].Cross(akDiff[2]); - afBary[1] = kE1cE2.Dot(kTmp)*fInvSqrArea; - kTmp = akDiff[1].Cross(akDiff[3]); - afBary[2] = kE1cE2.Dot(kTmp)*fInvSqrArea; - afBary[3] = (double)1.0 - afBary[1] - afBary[2]; - } - else if ( iMaxIndex == 2 ) - { - kTmp = akDiff[2].Cross(akDiff[3]); - afBary[0] = kE2cE0.Dot(kTmp)*fInvSqrArea; - afBary[1] = (double)0.0; - kTmp = akDiff[3].Cross(akDiff[0]); - afBary[2] = kE2cE0.Dot(kTmp)*fInvSqrArea; - afBary[3] = (double)1.0 - afBary[0] - afBary[2]; - } - else - { - akDiff[3] = *this - rkV2; - kTmp = akDiff[3].Cross(kE12); - afBary[0] = kE02cE12.Dot(kTmp)*fInvSqrArea; - kTmp = kE02.Cross(akDiff[3]); - afBary[1] = kE02cE12.Dot(kTmp)*fInvSqrArea; - afBary[2] = (double)1.0 - afBary[0] - afBary[1]; - afBary[3] = (double)0.0; - } - } - else - { - // The tetrahedron is potentially a sliver. Determine the edge of - // maximum length and compute barycentric coordinates with respect - // to that edge. - double fMaxSqrLength = akDiff[0].SquaredLength(); - iMaxIndex = 0; // <V0,V3> - double fSqrLength = akDiff[1].SquaredLength(); - if ( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 1; // <V1,V3> - fMaxSqrLength = fSqrLength; - } - fSqrLength = akDiff[2].SquaredLength(); - if ( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 2; // <V2,V3> - fMaxSqrLength = fSqrLength; - } - fSqrLength = kE02.SquaredLength(); - if ( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 3; // <V0,V2> - fMaxSqrLength = fSqrLength; - } - fSqrLength = kE12.SquaredLength(); - if ( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 4; // <V1,V2> - fMaxSqrLength = fSqrLength; - } - GbVector3D kE01 = rkV0 - rkV1; - fSqrLength = kE01.SquaredLength(); - if ( fSqrLength > fMaxSqrLength ) - { - iMaxIndex = 5; // <V0,V1> - fMaxSqrLength = fSqrLength; - } + double fDet = akDiff[0].Dot(akDiff[1].Cross(akDiff[2])); + GbVector3D kE1cE2 = akDiff[1].Cross(akDiff[2]); + GbVector3D kE2cE0 = akDiff[2].Cross(akDiff[0]); + GbVector3D kE0cE1 = akDiff[0].Cross(akDiff[1]); + if (std::fabs(fDet) > UbMath::Epsilon<double>::val()) { + double fInvDet = ((double)1.0) / fDet; + afBary[0] = akDiff[3].Dot(kE1cE2) * fInvDet; + afBary[1] = akDiff[3].Dot(kE2cE0) * fInvDet; + afBary[2] = akDiff[3].Dot(kE0cE1) * fInvDet; + afBary[3] = (double)1.0 - afBary[0] - afBary[1] - afBary[2]; + } else { + // The tetrahedron is potentially flat. Determine the face of + // maximum area and compute barycentric coordinates with respect + // to that face. + GbVector3D kE02 = rkV0 - rkV2; + GbVector3D kE12 = rkV1 - rkV2; + GbVector3D kE02cE12 = kE02.Cross(kE12); + double fMaxSqrArea = kE02cE12.SquaredLength(); + int iMaxIndex = 3; + double fSqrArea = kE0cE1.SquaredLength(); + if (fSqrArea > fMaxSqrArea) { + iMaxIndex = 0; + fMaxSqrArea = fSqrArea; + } + fSqrArea = kE1cE2.SquaredLength(); + if (fSqrArea > fMaxSqrArea) { + iMaxIndex = 1; + fMaxSqrArea = fSqrArea; + } + fSqrArea = kE2cE0.SquaredLength(); + if (fSqrArea > fMaxSqrArea) { + iMaxIndex = 2; + fMaxSqrArea = fSqrArea; + } - if ( fMaxSqrLength > UbMath::Epsilon<double>::val() ) - { - double fInvSqrLength = ((double)1.0)/fMaxSqrLength; - if ( iMaxIndex == 0 ) - { - // P-V3 = t*(V0-V3) - afBary[0] = akDiff[3].Dot(akDiff[0])*fInvSqrLength; - afBary[1] = (double)0.0; - afBary[2] = (double)0.0; - afBary[3] = (double)1.0 - afBary[0]; + if (fMaxSqrArea > UbMath::Epsilon<double>::val()) { + double fInvSqrArea = ((double)1.0) / fMaxSqrArea; + GbVector3D kTmp; + if (iMaxIndex == 0) { + kTmp = akDiff[3].Cross(akDiff[1]); + afBary[0] = kE0cE1.Dot(kTmp) * fInvSqrArea; + kTmp = akDiff[0].Cross(akDiff[3]); + afBary[1] = kE0cE1.Dot(kTmp) * fInvSqrArea; + afBary[2] = (double)0.0; + afBary[3] = (double)1.0 - afBary[0] - afBary[1]; + } else if (iMaxIndex == 1) { + afBary[0] = (double)0.0; + kTmp = akDiff[3].Cross(akDiff[2]); + afBary[1] = kE1cE2.Dot(kTmp) * fInvSqrArea; + kTmp = akDiff[1].Cross(akDiff[3]); + afBary[2] = kE1cE2.Dot(kTmp) * fInvSqrArea; + afBary[3] = (double)1.0 - afBary[1] - afBary[2]; + } else if (iMaxIndex == 2) { + kTmp = akDiff[2].Cross(akDiff[3]); + afBary[0] = kE2cE0.Dot(kTmp) * fInvSqrArea; + afBary[1] = (double)0.0; + kTmp = akDiff[3].Cross(akDiff[0]); + afBary[2] = kE2cE0.Dot(kTmp) * fInvSqrArea; + afBary[3] = (double)1.0 - afBary[0] - afBary[2]; + } else { + akDiff[3] = *this - rkV2; + kTmp = akDiff[3].Cross(kE12); + afBary[0] = kE02cE12.Dot(kTmp) * fInvSqrArea; + kTmp = kE02.Cross(akDiff[3]); + afBary[1] = kE02cE12.Dot(kTmp) * fInvSqrArea; + afBary[2] = (double)1.0 - afBary[0] - afBary[1]; + afBary[3] = (double)0.0; } - else if ( iMaxIndex == 1 ) - { - // P-V3 = t*(V1-V3) - afBary[0] = (double)0.0; - afBary[1] = akDiff[3].Dot(akDiff[1])*fInvSqrLength; - afBary[2] = (double)0.0; - afBary[3] = (double)1.0 - afBary[1]; + } else { + // The tetrahedron is potentially a sliver. Determine the edge of + // maximum length and compute barycentric coordinates with respect + // to that edge. + double fMaxSqrLength = akDiff[0].SquaredLength(); + iMaxIndex = 0; // <V0,V3> + double fSqrLength = akDiff[1].SquaredLength(); + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 1; // <V1,V3> + fMaxSqrLength = fSqrLength; } - else if ( iMaxIndex == 2 ) - { - // P-V3 = t*(V2-V3) - afBary[0] = (double)0.0; - afBary[1] = (double)0.0; - afBary[2] = akDiff[3].Dot(akDiff[2])*fInvSqrLength; - afBary[3] = (double)1.0 - afBary[2]; + fSqrLength = akDiff[2].SquaredLength(); + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 2; // <V2,V3> + fMaxSqrLength = fSqrLength; } - else if ( iMaxIndex == 3 ) - { - // P-V2 = t*(V0-V2) - akDiff[3] = *this - rkV2; - afBary[0] = akDiff[3].Dot(kE02)*fInvSqrLength; - afBary[1] = (double)0.0; - afBary[2] = (double)1.0 - afBary[0]; - afBary[3] = (double)0.0; + fSqrLength = kE02.SquaredLength(); + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 3; // <V0,V2> + fMaxSqrLength = fSqrLength; } - else if ( iMaxIndex == 4 ) - { - // P-V2 = t*(V1-V2) - akDiff[3] = *this - rkV2; - afBary[0] = (double)0.0; - afBary[1] = akDiff[3].Dot(kE12)*fInvSqrLength; - afBary[2] = (double)1.0 - afBary[1]; - afBary[3] = (double)0.0; + fSqrLength = kE12.SquaredLength(); + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 4; // <V1,V2> + fMaxSqrLength = fSqrLength; } - else - { - // P-V1 = t*(V0-V1) - akDiff[3] = *this - rkV1; - afBary[0] = akDiff[3].Dot(kE01)*fInvSqrLength; - afBary[1] = (double)1.0 - afBary[0]; - afBary[2] = (double)0.0; - afBary[3] = (double)0.0; + GbVector3D kE01 = rkV0 - rkV1; + fSqrLength = kE01.SquaredLength(); + if (fSqrLength > fMaxSqrLength) { + iMaxIndex = 5; // <V0,V1> + fMaxSqrLength = fSqrLength; } - } - else - { - // tetrahedron is a nearly a point, just return equal weights - afBary[0] = (double)0.25; - afBary[1] = afBary[0]; - afBary[2] = afBary[0]; - afBary[3] = afBary[0]; - } - } - } + + if (fMaxSqrLength > UbMath::Epsilon<double>::val()) { + double fInvSqrLength = ((double)1.0) / fMaxSqrLength; + if (iMaxIndex == 0) { + // P-V3 = t*(V0-V3) + afBary[0] = akDiff[3].Dot(akDiff[0]) * fInvSqrLength; + afBary[1] = (double)0.0; + afBary[2] = (double)0.0; + afBary[3] = (double)1.0 - afBary[0]; + } else if (iMaxIndex == 1) { + // P-V3 = t*(V1-V3) + afBary[0] = (double)0.0; + afBary[1] = akDiff[3].Dot(akDiff[1]) * fInvSqrLength; + afBary[2] = (double)0.0; + afBary[3] = (double)1.0 - afBary[1]; + } else if (iMaxIndex == 2) { + // P-V3 = t*(V2-V3) + afBary[0] = (double)0.0; + afBary[1] = (double)0.0; + afBary[2] = akDiff[3].Dot(akDiff[2]) * fInvSqrLength; + afBary[3] = (double)1.0 - afBary[2]; + } else if (iMaxIndex == 3) { + // P-V2 = t*(V0-V2) + akDiff[3] = *this - rkV2; + afBary[0] = akDiff[3].Dot(kE02) * fInvSqrLength; + afBary[1] = (double)0.0; + afBary[2] = (double)1.0 - afBary[0]; + afBary[3] = (double)0.0; + } else if (iMaxIndex == 4) { + // P-V2 = t*(V1-V2) + akDiff[3] = *this - rkV2; + afBary[0] = (double)0.0; + afBary[1] = akDiff[3].Dot(kE12) * fInvSqrLength; + afBary[2] = (double)1.0 - afBary[1]; + afBary[3] = (double)0.0; + } else { + // P-V1 = t*(V0-V1) + akDiff[3] = *this - rkV1; + afBary[0] = akDiff[3].Dot(kE01) * fInvSqrLength; + afBary[1] = (double)1.0 - afBary[0]; + afBary[2] = (double)0.0; + afBary[3] = (double)0.0; + } + } else { + // tetrahedron is a nearly a point, just return equal weights + afBary[0] = (double)0.25; + afBary[1] = afBary[0]; + afBary[2] = afBary[0]; + afBary[3] = afBary[0]; + } + } + } } //---------------------------------------------------------------------------- -void GbVector3D::Orthonormalize (GbVector3D& rkU, GbVector3D& rkV, GbVector3D& rkW) +void GbVector3D::Orthonormalize(GbVector3D &rkU, GbVector3D &rkV, GbVector3D &rkW) { - // If the input vectors are v0, v1, and v2, then the Gram-Schmidt - // orthonormalization produces vectors u0, u1, and u2 as follows, - // - // u0 = v0/|v0| - // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0| - // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1| - // - // where |A| indicates length of vector A and A*B indicates dot - // product of vectors A and B. + // If the input vectors are v0, v1, and v2, then the Gram-Schmidt + // orthonormalization produces vectors u0, u1, and u2 as follows, + // + // u0 = v0/|v0| + // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0| + // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1| + // + // where |A| indicates length of vector A and A*B indicates dot + // product of vectors A and B. - // compute u0 - rkU.Normalize(); + // compute u0 + rkU.Normalize(); - // compute u1 - double fDot0 = rkU.Dot(rkV); - rkV -= fDot0*rkU; - rkV.Normalize(); + // compute u1 + double fDot0 = rkU.Dot(rkV); + rkV -= fDot0 * rkU; + rkV.Normalize(); - // compute u2 - double fDot1 = rkV.Dot(rkW); - fDot0 = rkU.Dot(rkW); - rkW -= fDot0*rkU + fDot1*rkV; - rkW.Normalize(); + // compute u2 + double fDot1 = rkV.Dot(rkW); + fDot0 = rkU.Dot(rkW); + rkW -= fDot0 * rkU + fDot1 * rkV; + rkW.Normalize(); } //---------------------------------------------------------------------------- -void GbVector3D::Orthonormalize (GbVector3D* akV) -{ - Orthonormalize(akV[0],akV[1],akV[2]); -} +void GbVector3D::Orthonormalize(GbVector3D *akV) { Orthonormalize(akV[0], akV[1], akV[2]); } //---------------------------------------------------------------------------- -void GbVector3D::GenerateOrthonormalBasis (GbVector3D& rkU, GbVector3D& rkV, - GbVector3D& rkW, bool bUnitLengthW) +void GbVector3D::GenerateOrthonormalBasis(GbVector3D &rkU, GbVector3D &rkV, GbVector3D &rkW, bool bUnitLengthW) { - if ( !bUnitLengthW ) - rkW.Normalize(); + if (!bUnitLengthW) + rkW.Normalize(); - double fInvLength; + double fInvLength; - if ( std::fabs(rkW.m_afTuple[0]) >= - std::fabs(rkW.m_afTuple[1]) ) - { - // W.x or W.z is the largest magnitude component, swap them - fInvLength = UbMath::invSqrt(rkW.m_afTuple[0]*rkW.m_afTuple[0] + rkW.m_afTuple[2]*rkW.m_afTuple[2]); - rkU.m_afTuple[0] = -rkW.m_afTuple[2]*fInvLength; - rkU.m_afTuple[1] = (double)0.0; - rkU.m_afTuple[2] = +rkW.m_afTuple[0]*fInvLength; - } - else - { - // W.y or W.z is the largest magnitude component, swap them - fInvLength = UbMath::invSqrt(rkW.m_afTuple[1]*rkW.m_afTuple[1] + rkW.m_afTuple[2]*rkW.m_afTuple[2]); - rkU.m_afTuple[0] = (double)0.0; - rkU.m_afTuple[1] = +rkW.m_afTuple[2]*fInvLength; - rkU.m_afTuple[2] = -rkW.m_afTuple[1]*fInvLength; - } + if (std::fabs(rkW.m_afTuple[0]) >= std::fabs(rkW.m_afTuple[1])) { + // W.x or W.z is the largest magnitude component, swap them + fInvLength = UbMath::invSqrt(rkW.m_afTuple[0] * rkW.m_afTuple[0] + rkW.m_afTuple[2] * rkW.m_afTuple[2]); + rkU.m_afTuple[0] = -rkW.m_afTuple[2] * fInvLength; + rkU.m_afTuple[1] = (double)0.0; + rkU.m_afTuple[2] = +rkW.m_afTuple[0] * fInvLength; + } else { + // W.y or W.z is the largest magnitude component, swap them + fInvLength = UbMath::invSqrt(rkW.m_afTuple[1] * rkW.m_afTuple[1] + rkW.m_afTuple[2] * rkW.m_afTuple[2]); + rkU.m_afTuple[0] = (double)0.0; + rkU.m_afTuple[1] = +rkW.m_afTuple[2] * fInvLength; + rkU.m_afTuple[2] = -rkW.m_afTuple[1] * fInvLength; + } - rkV = rkW.Cross(rkU); + rkV = rkW.Cross(rkU); } //---------------------------------------------------------------------------- - diff --git a/src/basics/geometry3d/GbVector3D.h b/src/basics/geometry3d/GbVector3D.h index 9bf699fa2..f92ae5ae2 100644 --- a/src/basics/geometry3d/GbVector3D.h +++ b/src/basics/geometry3d/GbVector3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids 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 +// +// VirtualFluids 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 VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,9 +32,9 @@ //======================================================================================= #ifndef GBVECTOR3D_H #define GBVECTOR3D_H - -#include <cfloat> -#include <cassert> + +#include <cassert> +#include <cfloat> #include <string> #include <PointerDefinitions.h> @@ -42,89 +42,87 @@ class GbPoint3D; //! \brief This Class provides basic 3D vector objects. -class GbVector3D +class GbVector3D { public: - // construction - GbVector3D (); - GbVector3D (const double& fX1, const double& fX2, const double& fX3); - GbVector3D (const GbVector3D& rkV); - GbVector3D (const GbPoint3D& rkV); + // construction + GbVector3D(); + GbVector3D(const double &fX1, const double &fX2, const double &fX3); + GbVector3D(const GbVector3D &rkV); + GbVector3D(const GbPoint3D &rkV); std::string toString(); // coordinate access - operator const double* () const; - operator double* (); - double operator[] (int i) const; - double& operator[] (int i); - double X1 () const; - double& X1 (); - double X2 () const; - double& X2 (); - double X3 () const; - double& X3 (); + operator const double *() const; + operator double *(); + double operator[](int i) const; + double &operator[](int i); + double X1() const; + double &X1(); + double X2() const; + double &X2(); + double X3() const; + double &X3(); // assignment - GbVector3D& operator= (const GbVector3D& rkV); + GbVector3D &operator=(const GbVector3D &rkV); // comparison - bool operator== (const GbVector3D& rkV) const; - bool operator!= (const GbVector3D& rkV) const; - bool operator< (const GbVector3D& rkV) const; - bool operator<= (const GbVector3D& rkV) const; - bool operator> (const GbVector3D& rkV) const; - bool operator>= (const GbVector3D& rkV) const; + bool operator==(const GbVector3D &rkV) const; + bool operator!=(const GbVector3D &rkV) const; + bool operator<(const GbVector3D &rkV) const; + bool operator<=(const GbVector3D &rkV) const; + bool operator>(const GbVector3D &rkV) const; + bool operator>=(const GbVector3D &rkV) const; // arithmetic operations - GbVector3D operator+ (const GbVector3D& rkV) const; - GbVector3D operator- (const GbVector3D& rkV) const; - GbVector3D operator* (const double& fScalar) const; - GbVector3D operator/ (const double& fScalar) const; - GbVector3D operator- () const; + GbVector3D operator+(const GbVector3D &rkV) const; + GbVector3D operator-(const GbVector3D &rkV) const; + GbVector3D operator*(const double &fScalar) const; + GbVector3D operator/(const double &fScalar) const; + GbVector3D operator-() const; // arithmetic updates - GbVector3D& operator+= (const GbVector3D& rkV); - GbVector3D& operator-= (const GbVector3D& rkV); - GbVector3D& operator*= (const double& fScalar); - GbVector3D& operator/= (const double& fScalar); + GbVector3D &operator+=(const GbVector3D &rkV); + GbVector3D &operator-=(const GbVector3D &rkV); + GbVector3D &operator*=(const double &fScalar); + GbVector3D &operator/=(const double &fScalar); - GbVector3D Add(GbVector3D& vector); - GbVector3D Subtract(GbVector3D& vector); - GbVector3D Scale(const double& x); + GbVector3D Add(GbVector3D &vector); + GbVector3D Subtract(GbVector3D &vector); + GbVector3D Scale(const double &x); // vector operations - double Length () const; - double SquaredLength () const; - double Dot (const GbVector3D& rkV) const; - double Normalize (); + double Length() const; + double SquaredLength() const; + double Dot(const GbVector3D &rkV) const; + double Normalize(); // The cross products are computed using the right-handed rule. Be aware // that some graphics APIs use a left-handed rule. If you have to compute // a cross product with these functions and send the result to the API // that expects left-handed, you will need to change sign on the vector // (replace each component value c by -c). - GbVector3D Cross (const GbVector3D& rkV) const; - GbVector3D UnitCross (const GbVector3D& rkV) const; + GbVector3D Cross(const GbVector3D &rkV) const; + GbVector3D UnitCross(const GbVector3D &rkV) const; // Compute the barycentric coordinates of the point with respect to the // tetrahedron <V0,V1,V2,V3>, P = b0*V0 + b1*V1 + b2*V2 + b3*V3, where // b0 + b1 + b2 + b3 = 1. - void GetBarycentrics (const GbVector3D& rkV0, - const GbVector3D& rkV1, const GbVector3D& rkV2, - const GbVector3D& rkV3, double afBary[4]) const; + void GetBarycentrics(const GbVector3D &rkV0, const GbVector3D &rkV1, const GbVector3D &rkV2, const GbVector3D &rkV3, + double afBary[4]) const; // Gram-Schmidt orthonormalization. Take linearly independent vectors // U, V, and W and compute an orthonormal set (unit length, mutually // perpendicular). - static void Orthonormalize (GbVector3D& rkU, GbVector3D& rkV, GbVector3D& rkW); - static void Orthonormalize (GbVector3D* akV); + static void Orthonormalize(GbVector3D &rkU, GbVector3D &rkV, GbVector3D &rkW); + static void Orthonormalize(GbVector3D *akV); // Input W must be initialized to a nonzero vector, output is {U,V,W}, // an orthonormal basis. A hint is provided about whether or not W // is already unit length. - static void GenerateOrthonormalBasis (GbVector3D& rkU, GbVector3D& rkV, - GbVector3D& rkW, bool bUnitLengthW); + static void GenerateOrthonormalBasis(GbVector3D &rkU, GbVector3D &rkV, GbVector3D &rkW, bool bUnitLengthW); // special vectors static const GbVector3D ZERO; @@ -134,11 +132,11 @@ public: private: // support for comparisons - int CompareArrays (const GbVector3D& rkV) const; + int CompareArrays(const GbVector3D &rkV) const; double m_afTuple[3]; }; -GbVector3D operator* (const double& fScalar, const GbVector3D& rkV); +GbVector3D operator*(const double &fScalar, const GbVector3D &rkV); -#endif //GBVECTOR3D_H +#endif // GBVECTOR3D_H -- GitLab