From 5715fc07ae53a26b9b617e13b08581a47d7a8d8b Mon Sep 17 00:00:00 2001
From: Lukas Werner <lks.werner@fau.de>
Date: Wed, 21 Mar 2018 16:22:13 +0100
Subject: [PATCH] Remove unnecessary functionalities

---
 src/pe/ccd/HashGrids.cpp        |  2 -
 src/pe/ccd/HashGrids.h          |  5 +-
 src/pe/raytracing/Raytracer.cpp | 83 ---------------------------------
 src/pe/raytracing/Raytracer.h   | 66 --------------------------
 4 files changed, 1 insertion(+), 155 deletions(-)

diff --git a/src/pe/ccd/HashGrids.cpp b/src/pe/ccd/HashGrids.cpp
index 8b7b001c7..f2bdc9c83 100644
--- a/src/pe/ccd/HashGrids.cpp
+++ b/src/pe/ccd/HashGrids.cpp
@@ -1179,8 +1179,6 @@ bool HashGrids::powerOfTwo( size_t number )
 }
 //*************************************************************************************************
 
-
-uint64_t HashGrids::intersectionTestCount = 0; //ToDo remove again
    
 //=================================================================================================
 //
diff --git a/src/pe/ccd/HashGrids.h b/src/pe/ccd/HashGrids.h
index b6f61458f..ef211a7e4 100644
--- a/src/pe/ccd/HashGrids.h
+++ b/src/pe/ccd/HashGrids.h
@@ -99,9 +99,7 @@ public:
    static const size_t gridActivationThreshold;
    static const real_t hierarchyFactor;
    //**********************************************************************************************
-   
-   static uint64_t intersectionTestCount; // ToDo remove again
-   
+      
 private:
    //**Type definitions****************************************************************************
    //! Vector for storing (handles to) rigid bodies.
@@ -583,7 +581,6 @@ BodyID HashGrids::HashGrid::getBodyIntersectionForBlockCell(const Vector3<int32_
                continue;
             }
                
-            HashGrids::intersectionTestCount++;
             bool intersects = SingleCast<BodyTuple, raytracing::IntersectsFunctor, bool>::execute(cellBody, intersectsFunc);
             if (intersects && t_local < t_closest) {
                body = cellBody;
diff --git a/src/pe/raytracing/Raytracer.cpp b/src/pe/raytracing/Raytracer.cpp
index 9f6bf4b46..fb3ce40c5 100644
--- a/src/pe/raytracing/Raytracer.cpp
+++ b/src/pe/raytracing/Raytracer.cpp
@@ -89,8 +89,6 @@ Raytracer::Raytracer(const shared_ptr<BlockStorage> forest, const BlockDataID st
    lighting_(lighting),
    backgroundColor_(backgroundColor),
    blockAABBIntersectionPadding_(blockAABBIntersectionPadding),
-   tBufferOutputEnabled_(false),
-   tBufferOutputDirectory_("."),
    imageOutputEnabled_(true),
    localImageOutputEnabled_(false),
    imageOutputDirectory_("."),
@@ -145,14 +143,6 @@ Raytracer::Raytracer(const shared_ptr<BlockStorage> forest, const BlockDataID st
    fov_vertical_ = config.getParameter<real_t>("fov_vertical");
    antiAliasFactor_ = config.getParameter<uint16_t>("antiAliasFactor", 1);
    
-   if (config.isDefined("tbuffer_output_directory")) {
-      setTBufferOutputEnabled(true);
-      setTBufferOutputDirectory(config.getParameter<std::string>("tbuffer_output_directory", "."));
-      WALBERLA_LOG_INFO_ON_ROOT("t buffers will be written to " << getTBufferOutputDirectory() << ".");
-   } else {
-      setTBufferOutputEnabled(false);
-   }
-   
    setLocalImageOutputEnabled(config.getParameter<bool>("local_image_output_enabled", false));
       
    if (config.isDefined("image_output_directory")) {
@@ -285,68 +275,6 @@ std::string Raytracer::getOutputFilename(const std::string& base, size_t timeste
    return fileNameStream.str();
 }
 
-/*!\brief Writes the depth values of the intersections buffer to an image file in the tBuffer output directory.
- * \param intersectionsBuffer Buffer with intersection info for each pixel.
- * \param timestep Timestep this image is from.
- * \param isGlobalImage Whether this image is the fully stitched together one.
- */
-void Raytracer::writeDepthsToFile(const std::vector<BodyIntersectionInfo>& intersectionsBuffer,
-                                   size_t timestep, bool isGlobalImage) const {
-   writeDepthsToFile(intersectionsBuffer, getOutputFilename("tbuffer", timestep, isGlobalImage));
-}
-
-/*!\brief Writes the depth values of the intersections buffer to an image file in the tBuffer output directory.
- * \param intersectionsBuffer Buffer with intersection info for each pixel.
- * \param fileName Name of the output file.
- */
-void Raytracer::writeDepthsToFile(const std::vector<BodyIntersectionInfo>& intersectionsBuffer,
-                                  const std::string& fileName) const {
-   real_t inf = std::numeric_limits<real_t>::max();
-   
-   real_t t_max = 1;
-   real_t t_min = inf;
-   for (size_t x = 0; x < pixelsHorizontal_; x++) {
-      for (size_t y = 0; y < pixelsVertical_; y++) {
-         size_t i = coordinateToArrayIndex(x, y);
-         real_t t = real_c(intersectionsBuffer[i].t);
-         if (t < t_min) {
-            t_min = t;
-         }
-      }
-   }
-   if (realIsIdentical(t_min, inf)) t_min = 0;
-   
-   t_max = forest_->getDomain().maxDistance(cameraPosition_);
-   
-   filesystem::path dir (getTBufferOutputDirectory());
-   filesystem::path file (fileName);
-   filesystem::path fullPath = dir / file;
-   
-   std::vector<u_char> lodeTBuffer(pixelsHorizontal_*pixelsVertical_);
-   
-   uint32_t l = 0;
-   for (size_t y = pixelsVertical_-1; y > 0; y--) {
-      for (size_t x = 0; x < pixelsHorizontal_; x++) {
-         size_t i = coordinateToArrayIndex(x, y);
-         u_char g = 0;
-         real_t t = real_c(intersectionsBuffer[i].t);
-         if (realIsIdentical(t, inf)) {
-            g = (u_char)0;
-         } else {
-            real_t t_scaled = (1-(t-t_min)/(t_max-t_min));
-            g = (u_char)(255 * std::max(std::min(t_scaled, real_t(1)), real_t(0)));
-         }
-         lodeTBuffer[l] = g;
-         l++;
-      }
-   }
-   
-   uint32_t error = lodepng::encode(fullPath.string(), lodeTBuffer, getPixelsHorizontal(), getPixelsVertical(), LCT_GREY);
-   if(error) {
-      WALBERLA_LOG_WARNING("lodePNG error " << error << " when trying to save tbuffer file to " << fullPath.string() << ": " << lodepng_error_text(error));
-   }
-}
-
 /*!\brief Writes the image of the current intersection buffer to a file in the image output directory.
  * \param intersectionsBuffer Buffer with intersection info for each pixel.
  * \param timestep Timestep this image is from.
@@ -488,12 +416,6 @@ void Raytracer::localOutput(const std::vector<BodyIntersectionInfo>& intersectio
          if (tt != NULL) tt->stop("Local Output");
       }
    }
-   
-   if (getTBufferOutputEnabled()) {
-      if (tt != NULL) tt->start("Local Output");
-      writeDepthsToFile(intersectionsBuffer, timestep);
-      if (tt != NULL) tt->stop("Local Output");
-   }
 }
 
 void Raytracer::output(const std::vector<BodyIntersectionInfo>& intersectionsBuffer, size_t timestep, WcTimingTree* tt) {
@@ -502,15 +424,10 @@ void Raytracer::output(const std::vector<BodyIntersectionInfo>& intersectionsBuf
       if (getImageOutputEnabled()) {
          writeImageToFile(intersectionsBuffer, timestep, true);
       }
-      if (getTBufferOutputEnabled()) {
-         writeDepthsToFile(intersectionsBuffer, timestep, true);
-      }
       if (tt != NULL) tt->stop("Output");
    }
 }
 
-uint64_t Raytracer::naiveIntersectionTestCount = 0;
-
 }
 }
 }
diff --git a/src/pe/raytracing/Raytracer.h b/src/pe/raytracing/Raytracer.h
index 8d77d63ee..5c56256a5 100644
--- a/src/pe/raytracing/Raytracer.h
+++ b/src/pe/raytracing/Raytracer.h
@@ -125,9 +125,6 @@ private:
    real_t blockAABBIntersectionPadding_; /*!< The padding applied in block AABB intersection pretesting, as
                                           * some objects within a block might protrude from the block's AABB.*/
    
-   bool tBufferOutputEnabled_; //!< Enable / disable dumping the tbuffer to file.
-   std::string tBufferOutputDirectory_; //!< Path to the tbuffer output directory.
-   
    bool imageOutputEnabled_;  //!< Enable / disable writing images to file.
    bool localImageOutputEnabled_; //!< Enable / disable writing images of the local process to file.
    std::string imageOutputDirectory_; //!< Path to the image output directory.
@@ -143,8 +140,6 @@ private:
                                                            * a given body should be visible in the final image. */
    Algorithm raytracingAlgorithm_;    //!< Algorithm to use while intersection testing.
    ReductionMethod reductionMethod_; //!< Reduction method used for assembling the image from all processes.
-   
-   static uint64_t naiveIntersectionTestCount;
    //@}
    
    /*!\name Member variables for raytracing geometry */
@@ -176,8 +171,6 @@ public:
    inline const Vec3& getLookAtPoint() const;
    inline const Vec3& getUpVector() const;
    inline const Color& getBackgroundColor() const;
-   inline bool getTBufferOutputEnabled() const;
-   inline const std::string& getTBufferOutputDirectory() const;
    inline bool getImageOutputEnabled() const;
    inline bool getLocalImageOutputEnabled() const;
    inline const std::string& getImageOutputDirectory() const;
@@ -187,8 +180,6 @@ public:
    /*!\name Set functions */
    //@{
    inline void setBackgroundColor(const Color& color);
-   inline void setTBufferOutputEnabled(const bool enabled);
-   inline void setTBufferOutputDirectory(const std::string& path);
    inline void setImageOutputEnabled(const bool enabled);
    inline void setLocalImageOutputEnabled(const bool enabled);
    inline void setImageOutputDirectory(const std::string& path);
@@ -213,10 +204,6 @@ private:
                WcTimingTree* tt = NULL);
 
    std::string getOutputFilename(const std::string& base, size_t timestep, bool isGlobalImage) const;
-   void writeDepthsToFile(const std::vector<BodyIntersectionInfo>& intersectionsBuffer,
-                          size_t timestep, bool isGlobalImage = false) const;
-   void writeDepthsToFile(const std::vector<BodyIntersectionInfo>& intersectionsBuffer,
-                          const std::string& fileName) const;
    void writeImageToFile(const std::vector<BodyIntersectionInfo>& intersectionsBuffer,
                          size_t timestep, bool isGlobalImage = false) const;
    void writeImageToFile(const std::vector<BodyIntersectionInfo>& intersectionsBuffer,
@@ -305,22 +292,6 @@ inline const Color& Raytracer::getBackgroundColor() const {
    return backgroundColor_;
 }
 
-/*!\brief Returns true if tbuffer output to a file is enabled.
- *
- * \return True if tbuffer output enabled, otherwise false.
- */
-inline bool Raytracer::getTBufferOutputEnabled() const {
-   return tBufferOutputEnabled_;
-}
-
-/*!\brief Returns the directory where the tbuffer output file will be saved in.
- *
- * \return Path to the tbuffer output directory.
- */
-inline const std::string& Raytracer::getTBufferOutputDirectory() const {
-   return tBufferOutputDirectory_;
-}
-   
 /*!\brief Returns true if image output to a file is enabled.
  *
  * \return True if image output enabled, otherwise false.
@@ -360,23 +331,6 @@ inline void Raytracer::setBackgroundColor(const Color& color) {
    backgroundColor_ = color;
 }
    
-/*!\brief Enable / disable outputting the tBuffer to a file in the specified directory.
- * \param enabled Set to true / false to enable / disable tbuffer output.
- */
-inline void Raytracer::setTBufferOutputEnabled(const bool enabled) {
-   tBufferOutputEnabled_ = enabled;
-}
-
-/*!\brief Enable / disable outputting the tBuffer to a file in the specified directory.
- * \param enabled Set to true / false to enable / disable tbuffer output.
- */
-inline void Raytracer::setTBufferOutputDirectory(const std::string& path) {
-   filesystem::path dir (path);
-   WALBERLA_CHECK(filesystem::exists(dir) && filesystem::is_directory(dir), "Tbuffer output directory " << path << " is invalid.");
-   
-   tBufferOutputDirectory_ = path;
-}
-   
 /*!\brief Enable / disable outputting images in the specified directory.
  * \param enabled Set to true / false to enable / disable image output.
  */
@@ -510,8 +464,6 @@ inline void Raytracer::traceRayNaively(const Ray& ray, BodyID& body_closest, rea
          }
          
          bool intersects = SingleCast<BodyTypeTuple, IntersectsFunctor, bool>::execute(*bodyIt, func);
-         Raytracer::naiveIntersectionTestCount++;
-         
          if (intersects && t < t_closest) {
             // body was shot by ray and is currently closest to camera
             t_closest = t;
@@ -579,12 +531,8 @@ void Raytracer::generateImage(const size_t timestep, WcTimingTree* tt) {
          hashgrids->update();
       }
       if (tt != NULL) tt->stop("HashGrids Update");
-      
-      ccd::HashGrids::intersectionTestCount = 0;
    }
    
-   Raytracer::naiveIntersectionTestCount = 0;
-   
    real_t t, t_closest;
    Vec3 n;
    Vec3 n_closest;
@@ -651,20 +599,6 @@ void Raytracer::generateImage(const size_t timestep, WcTimingTree* tt) {
    }
    if (tt != NULL) tt->stop("Intersection Testing");
 
-   if (raytracingAlgorithm_ == RAYTRACE_COMPARE_BOTH || raytracingAlgorithm_ == RAYTRACE_COMPARE_BOTH_STRICTLY) {
-      uint64_t naiveTests = Raytracer::naiveIntersectionTestCount;
-      uint64_t hashgridsTests = ccd::HashGrids::intersectionTestCount;
-      mpi::reduceInplace(naiveTests, mpi::SUM, 0);
-      mpi::reduceInplace(hashgridsTests, mpi::SUM, 0);
-      WALBERLA_ROOT_SECTION() {
-         uint64_t savedIntersections = naiveTests-hashgridsTests;
-         real_t savedIntersectionsPercentage = (real_t(1)-real_c(hashgridsTests)/real_c(naiveTests))*100;
-         WALBERLA_LOG_INFO("Intersection statistics (processes: " << mpi::MPIManager::instance()->numProcesses() << "):");
-         WALBERLA_LOG_INFO(" Naive tests:     " << std::setw(10) << naiveTests);
-         WALBERLA_LOG_INFO(" HashGrids tests: " << std::setw(10) << hashgridsTests);
-         WALBERLA_LOG_INFO(" Saved tests:     " << std::setw(10) << savedIntersections << " (" << std::setprecision(4) << savedIntersectionsPercentage << "%)");
-      }
-   }
    if (raytracingAlgorithm_ == RAYTRACE_COMPARE_BOTH || raytracingAlgorithm_ == RAYTRACE_COMPARE_BOTH_STRICTLY) {
       if (pixelErrors > 0) {
          WALBERLA_LOG_WARNING(pixelErrors << " pixel errors found!");
-- 
GitLab