<commit_before>// ======================================================================== //
// Copyright 2016 SURVICE Engineering Company                               //
// Copyright 2009-2016 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "imgui3D.h"

#include <imgui.h>
#include "imgui_impl_glfw_gl3.h"

#include "ospcommon/utility/CodeTimer.h"
#include "ospcommon/utility/getEnvVar.h"
#include "ospray/version.h"

#include <stdio.h>
#include <GLFW/glfw3.h>

#ifdef _WIN32
#  define snprintf(buf,len, format,...) _snprintf_s(buf, len,len, format, __VA_ARGS__)
#  ifndef WIN32_LEAN_AND_MEAN
#    define WIN32_LEAN_AND_MEAN
#  endif
#  define _USE_MATH_DEFINES
#  include <math.h> // M_PI
#else
#  include <sys/times.h>
#endif

#include <fstream>
#include <sstream>
#include <stdexcept>
#include <string>

extern "C" void glDrawPixels( GLsizei width, GLsizei height,
                              GLenum format, GLenum type,
                              const GLvoid *pixels );

using ospcommon::utility::getEnvVar;

namespace ospray {
  namespace imgui3D {

    bool dumpScreensDuringAnimation = false;
    bool ImGui3DWidget::showGui = false;

    static ImGui3DWidget *currentWidget = nullptr;

    // Class definitions //////////////////////////////////////////////////////

    /*! write given frame buffer to file, in PPM P6 format. */
    void saveFrameBufferToFile(const char *fileName,
                               const uint32_t *pixel,
                               const uint32_t sizeX, const uint32_t sizeY)
    {
      FILE *file = fopen(fileName,"wb");
      if (!file) {
        std::cerr << "#osp:glut3D: Warning - could not create screenshot file '"
                  << fileName << "'" << std::endl;
        return;
      }
      fprintf(file,"P6\n%i %i\n255\n",sizeX,sizeY);
      unsigned char *out = (unsigned char *)alloca(3*sizeX);
      for (size_t y = 0; y < sizeY; y++) {
        const unsigned char *in =
            (const unsigned char *)&pixel[(sizeY-1-y)*sizeX];
        for (size_t x = 0; x < sizeX; x++) {
          out[3*x+0] = in[4*x+0];
          out[3*x+1] = in[4*x+1];
          out[3*x+2] = in[4*x+2];
        }
        fwrite(out, 3*sizeX, sizeof(char), file);
      }
      fprintf(file,"\n");
      fclose(file);
      std::cout << "#osp:glut3D: saved framebuffer to file "
                << fileName << std::endl;
    }

    /*! currently active window */
    ImGui3DWidget *ImGui3DWidget::activeWindow = nullptr;
    vec2i ImGui3DWidget::defaultInitSize(1024,768);

    bool ImGui3DWidget::animating = false;

    // InspectCenter Glut3DWidget::INSPECT_CENTER;
    /*! viewport as specified on the command line */
    ImGui3DWidget::ViewPort *viewPortFromCmdLine = nullptr;

    // ------------------------------------------------------------------
    // implementation of glut3d::viewPorts
    // ------------------------------------------------------------------
    ImGui3DWidget::ViewPort::ViewPort() :
      modified(true),
      from(0,0,-1),
      at(0,0,0),
      up(0,1,0),
      openingAngle(60.f),<commit_msg>Use utility to save image<commit_after>// ======================================================================== //
// Copyright 2016 SURVICE Engineering Company                               //
// Copyright 2009-2016 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "imgui3D.h"

#include <imgui.h>
#include "imgui_impl_glfw_gl3.h"

#include "ospcommon/utility/CodeTimer.h"
#include "ospcommon/utility/getEnvVar.h"
#include "ospcommon/utility/SaveImage.h"
#include "ospray/version.h"

#include <stdio.h>
#include <GLFW/glfw3.h>

#ifdef _WIN32
#  define snprintf(buf,len, format,...) _snprintf_s(buf, len,len, format, __VA_ARGS__)
#  ifndef WIN32_LEAN_AND_MEAN
#    define WIN32_LEAN_AND_MEAN
#  endif
#  define _USE_MATH_DEFINES
#  include <math.h> // M_PI
#else
#  include <sys/times.h>
#endif

#include <fstream>
#include <sstream>
#include <stdexcept>
#include <string>

extern "C" void glDrawPixels( GLsizei width, GLsizei height,
                              GLenum format, GLenum type,
                              const GLvoid *pixels );

using ospcommon::utility::getEnvVar;

namespace ospray {
  namespace imgui3D {

    bool dumpScreensDuringAnimation = false;
    bool ImGui3DWidget::showGui = false;

    static ImGui3DWidget *currentWidget = nullptr;

    // Class definitions //////////////////////////////////////////////////////

    /*! write given frame buffer to file, in PPM P6 format. */
    void saveFrameBufferToFile(const char *fileName,
                               const uint32_t *pixel,
                               const uint32_t sizeX, const uint32_t sizeY)
    {
      utility::writePPM(fileName, sizeX, sizeY, pixel);
      std::cout << "#osp:glut3D: saved framebuffer to file " << fileName
        << std::endl;
    }

    /*! currently active window */
    ImGui3DWidget *ImGui3DWidget::activeWindow = nullptr;
    vec2i ImGui3DWidget::defaultInitSize(1024,768);

    bool ImGui3DWidget::animating = false;

    // InspectCenter Glut3DWidget::INSPECT_CENTER;
    /*! viewport as specified on the command line */
    ImGui3DWidget::ViewPort *viewPortFromCmdLine = nullptr;

    // ------------------------------------------------------------------
    // implementation of glut3d::viewPorts
    // ------------------------------------------------------------------
    ImGui3DWidget::ViewPort::ViewPort() :
      modified(true),
      from(0,0,-1),
      at(0,0,0),
      up(0,1,0),
      openingAngle(60.f),
{'fraction_non_alphanumeric': 0.1881240147136101, 'fraction_numerical': 0.019442984760903836, 'mean_word_length': 1.6489213639526792, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137144', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1996, 'n_words': 529}