Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

PR for insitu_log branch #1059

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion core/include/mmcore/view/AbstractCallRender3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ namespace view {
this->camParams = camParams;
}


inline void SetCameraView(const vislib::math::Point<float, 3> pos, const vislib::math::Point<float, 3> la,
const vislib::math::Vector<float, 3> up) {
this->camParams->SetView(pos, la, up);
}

/**
* Assignment operator
Expand Down
11 changes: 8 additions & 3 deletions plugins/OSPRay_plugin/src/OSPRayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <sstream>
#include <stdint.h>

#define OSPRAY_MEASUREMENT 1

using namespace megamol::ospray;

/*
Expand Down Expand Up @@ -257,7 +259,7 @@ bool OSPRayRenderer::Render(megamol::core::Call& call) {
ospCommit(world);
auto t2 = std::chrono::high_resolution_clock::now();
const auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
vislib::sys::Log::DefaultLog.WriteMsg(242, "OSPRayRenderer: Commiting World took: %d microseconds", duration);
vislib::sys::Log::DefaultLog.WriteMsg(2, "OSPRayRenderer: Commiting World took: %d microseconds", duration);
}
if (material_has_changed && !data_has_changed) {
this->changeMaterial();
Expand Down Expand Up @@ -300,9 +302,12 @@ bool OSPRayRenderer::Render(megamol::core::Call& call) {

accum_time.amount += duration.count();
accum_time.count += 1;
if (accum_time.amount >= static_cast<unsigned long long int>(1e6)) {
#ifndef OSPRAY_MEASUREMENT
if (accum_time.amount >= static_cast<unsigned long long int>(1e6))
#endif
{
const unsigned long long int mean_rendertime = accum_time.amount / accum_time.count;
vislib::sys::Log::DefaultLog.WriteMsg(242, "OSPRayRenderer: Rendering took: %d microseconds", mean_rendertime);
vislib::sys::Log::DefaultLog.WriteMsg(2, "OSPRayRenderer: Rendering took: %d microseconds", mean_rendertime);
accum_time.count = 0;
accum_time.amount = 0;
}
Expand Down
14 changes: 12 additions & 2 deletions plugins/pbs/src/FBOTransmitter2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "FBOTransmitter2.h"

#include <array>
#include <chrono>

#include "glad/glad.h"

Expand Down Expand Up @@ -31,6 +32,8 @@
# include <unistd.h>
#endif

#define PBS_MEASUREMENTS 1

//#define _DEBUG 1

megamol::pbs::FBOTransmitter2::FBOTransmitter2()
Expand Down Expand Up @@ -194,10 +197,18 @@ void megamol::pbs::FBOTransmitter2::AfterRender(megamol::core::view::AbstractVie
vislib::sys::Log::DefaultLog.WriteInfo(
"IceT gets image with xoff: %d, yoff: %d, tile_width: %d, tile_height: %d\n", xoff, yoff, tile_width,
tile_height);
#endif
# ifdef PBS_MEASUREMENTS
auto const start = std::chrono::high_resolution_clock::now();
# endif
auto const icet_comp_image = icetCompositeImage(col_buf.data(), depth_buf.data(), tilevp, nullptr, nullptr,
static_cast<const IceTFloat*>(backgroundColor.data()));
# if _DEBUG
# ifdef PBS_MEASUREMENTS
auto const end = std::chrono::high_resolution_clock::now();
vislib::sys::Log::DefaultLog.WriteMsg(2, "FBOTransmitter2: Compositing Time %d ms",
std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
# endif
#if _DEBUG
vislib::sys::Log::DefaultLog.WriteInfo("FBOTransmitter2: IceT - Composite Image Done\n");
# endif

Expand Down Expand Up @@ -256,7 +267,6 @@ void megamol::pbs::FBOTransmitter2::AfterRender(megamol::core::view::AbstractVie

this->color_buf_read_->resize(col_buf.size());
this->depth_buf_read_->resize(depth_buf.size());

#ifdef WITH_MPI
// std::copy(col_buf.begin(), col_buf.end(), this->color_buf_read_->begin());
memcpy(this->color_buf_read_->data(), icet_col_buf, width * height * col_buf_el_size_);
Expand Down
148 changes: 148 additions & 0 deletions plugins/pbs/src/PNGWriter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#include "PNGWriter.h"
#include "vislib/sys/Path.h"


namespace megamol {
namespace pbs {

/*
* CinematicView::render2file_setup
*/
bool PNGWriter::setup(std::string _fullpath) {

// init png data struct
this->pngdata.buffer = nullptr;
this->pngdata.ptr = nullptr;
this->pngdata.infoptr = nullptr;

this->pngdata.path = vislib::sys::Path::GetDirectoryName(_fullpath.c_str());
this->pngdata.filename = _fullpath;

vislib::sys::Path::MakeDirectory(this->pngdata.path.c_str());

return true;
}




/*
* PNGWriter::render2file_write_png
*/
bool PNGWriter::render2file() {

// open final image file
if (!this->pngdata.file.Open(this->pngdata.filename.c_str(), vislib::sys::File::WRITE_ONLY,
vislib::sys::File::SHARE_EXCLUSIVE, vislib::sys::File::CREATE_OVERWRITE)) {
throw vislib::Exception("[PNGWriter] [startAnimRendering] Cannot open output file", __FILE__, __LINE__);
}

// init png lib
this->pngdata.ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, &this->pngError, &this->pngWarn);
if (this->pngdata.ptr == nullptr) {
throw vislib::Exception("[PNGWriter] [startAnimRendering] Cannot create png structure", __FILE__, __LINE__);
}
this->pngdata.infoptr = png_create_info_struct(this->pngdata.ptr);
if (this->pngdata.infoptr == nullptr) {
throw vislib::Exception("[PNGWriter] [startAnimRendering] Cannot create png info", __FILE__, __LINE__);
}
png_set_write_fn(this->pngdata.ptr, static_cast<void*>(&this->pngdata.file), &this->pngWrite, &this->pngFlush);
png_set_IHDR(this->pngdata.ptr, this->pngdata.infoptr, this->pngdata.width, this->pngdata.height, 8,
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

if (this->pngdata.buffer == nullptr) {
throw vislib::Exception(
"[PNGWriter] [writeTextureToPng] Failed to create Screenshot: Cannot read image data", __FILE__, __LINE__);
}

BYTE** rows = nullptr;
try {
rows = new BYTE*[this->pngdata.height];
for (UINT i = 0; i < this->pngdata.height; i++) {
rows[this->pngdata.height - (1 + i)] = this->pngdata.buffer + this->pngdata.bpp * i * this->pngdata.width;
}
png_set_rows(this->pngdata.ptr, this->pngdata.infoptr, rows);

png_write_png(this->pngdata.ptr, this->pngdata.infoptr, PNG_TRANSFORM_IDENTITY, nullptr);

ARY_SAFE_DELETE(rows);
} catch (...) {
if (rows != nullptr) {
ARY_SAFE_DELETE(rows);
}
throw;
}

if (this->pngdata.ptr != nullptr) {
if (this->pngdata.infoptr != nullptr) {
png_destroy_write_struct(&this->pngdata.ptr, &this->pngdata.infoptr);
} else {
png_destroy_write_struct(&this->pngdata.ptr, (png_infopp) nullptr);
}
}

try {
this->pngdata.file.Flush();
} catch (...) {
}
try {
this->pngdata.file.Close();
} catch (...) {
}

return true;
}


/*
* CinematicView::render2file_finish
*/
bool PNGWriter::finish() {

if (this->pngdata.ptr != nullptr) {
if (this->pngdata.infoptr != nullptr) {
png_destroy_write_struct(&this->pngdata.ptr, &this->pngdata.infoptr);
} else {
png_destroy_write_struct(&this->pngdata.ptr, (png_infopp) nullptr);
}
}

try {
this->pngdata.file.Flush();
} catch (...) {
}
try {
this->pngdata.file.Close();
} catch (...) {
}

//ARY_SAFE_DELETE(this->pngdata.buffer);

vislib::sys::Log::DefaultLog.WriteInfo("[PNGWriter] STOPPED rendering.");
return true;
}

void PNGWriter::set_buffer(BYTE* _buffer, unsigned _width, unsigned _height, unsigned int _bytesPerPixel = 4) {
if (_buffer != nullptr) {
// Create new byte buffer
this->pngdata.bpp = _bytesPerPixel;
this->pngdata.width = _width;
this->pngdata.height = _height;

//this->pngdata.buffer = new BYTE[this->pngdata.width * this->pngdata.height * this->pngdata.bpp];
//if (this->pngdata.buffer == nullptr) {
// throw vislib::Exception(
// "[PNGWriter] [startAnimRendering] Cannot allocate image buffer.", __FILE__, __LINE__);
//}
this->pngdata.buffer = _buffer;

} else {
this->pngdata.bpp = 0;
this->pngdata.width = 0;
this->pngdata.height = 0;
vislib::sys::Log::DefaultLog.WriteError("[PNGWriter] Input buffer is empty.");
}
}

} // namespace pbs
} // namespace megamol
87 changes: 87 additions & 0 deletions plugins/pbs/src/PNGWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once
#include "png.h"
#include "vislib/sys/File.h"
#include "vislib/sys/Log.h"
#include "vislib/sys/FastFile.h"
#include <chrono>
#include <string>

namespace megamol {
namespace pbs {

class PNGWriter {
public:

/** Render to file functions */
bool setup(std::string _fullpath);

/** */
bool render2file();

/** */
bool finish();

/** */
void set_buffer(BYTE* _buffer, unsigned int _width, unsigned int _height, unsigned int _bytesPerPixel);

/**
* Error handling function for png export
*
* @param pngPtr The png structure pointer
* @param msg The error message
*/
static void PNGAPI pngError(png_structp pngPtr, png_const_charp msg) {
throw vislib::Exception(msg, __FILE__, __LINE__);
}

/**
* Error handling function for png export
*
* @param pngPtr The png structure pointer
* @param msg The error message
*/
static void PNGAPI pngWarn(png_structp pngPtr, png_const_charp msg) {
vislib::sys::Log::DefaultLog.WriteMsg(vislib::sys::Log::LEVEL_WARN, "Png-Warning: %s\n", msg);
}

/**
* Write function for png export
*
* @param pngPtr The png structure pointer
* @param buf The pointer to the buffer to be written
* @param size The number of bytes to be written
*/
static void PNGAPI pngWrite(png_structp pngPtr, png_bytep buf, png_size_t size) {
vislib::sys::File* f = static_cast<vislib::sys::File*>(png_get_io_ptr(pngPtr));
f->Write(buf, size);
}

/**
* Flush function for png export
*
* @param pngPtr The png structure pointer
*/
static void PNGAPI pngFlush(png_structp pngPtr) {
vislib::sys::File* f = static_cast<vislib::sys::File*>(png_get_io_ptr(pngPtr));
f->Flush();
}



private:

struct pngData {
BYTE* buffer = nullptr;
vislib::sys::FastFile file;
unsigned int width;
unsigned int height;
unsigned int bpp;
std::string path;
std::string filename;
png_structp ptr = nullptr;
png_infop infoptr = nullptr;
} pngdata;

};
} // namespace pbs
} // namespace megamol
Loading