<commit_before>// ======================================================================== //
// 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 "ModelViewer.h"
#include "widgets/affineSpaceManipulator/HelperGeometry.h"
#include "FPSCounter.h"
// sg
#include "sg/SceneGraph.h"
#include "sg/Renderer.h"
// std
#include <sstream>

namespace ospray {
  namespace viewer {

    using std::cout;
    using std::endl;

    float autoRotateSpeed = 0.f;

    FPSCounter fps;

    OSPRayRenderWidget::OSPRayRenderWidget(Ref<sg::Renderer> renderer)
      : QAffineSpaceManipulator(QAffineSpaceManipulator::INSPECT),
        sgRenderer(renderer)
    {
      if (renderer->world) {
        box3f worldBounds = renderer->world->getBounds();
        if (!worldBounds.empty()) {
          float moveSpeed = .25*length(worldBounds.size());
          QAffineSpaceManipulator::setMoveSpeed(moveSpeed);
        }
      }
      Ref<sg::PerspectiveCamera> camera = renderer->camera.cast<sg::PerspectiveCamera>();
      if (camera) {
        frame->sourcePoint = camera->getFrom();
        frame->targetPoint = camera->getAt();
        frame->upVector    = camera->getUp();
        frame->orientation.vz = normalize(camera->getUp());
        frame->orientation.vy = normalize(camera->getAt() - camera->getFrom());
        frame->orientation.vx = normalize(cross(frame->orientation.vy,frame->orientation.vz));
      }
    }

    void OSPRayRenderWidget::setWorld(Ref<sg::World> world)
    {
      assert(sgRenderer);
      sgRenderer->setWorld(world);
      cout << "#ospQTV: world set, found "
           << sgRenderer->allNodes.size() << " nodes" << endl;
    }

    //! the QT callback that tells us that we have to redraw
    void OSPRayRenderWidget::redraw()
    {
      if (!sgRenderer) return;
      if (!sgRenderer->frameBuffer) return;
      if (!sgRenderer->camera) return;

      if (showFPS) {
        static int frameID = 0;
        if (frameID > 0) {
          fps.doneRender();
          printf("fps: %7.3f (smoothed: %7.3f)\n",fps.getFPS(),fps.getSmoothFPS());
        }
        fps.startRender();
        ++frameID;
      }

      sgRenderer->renderFrame();


      vec2i size = sgRenderer->frameBuffer->getSize();
      unsigned char *fbMem = sgRenderer->frameBuffer->map();
      glDrawPixels(size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, fbMem);
      sgRenderer->frameBuffer->unmap(fbMem);

      if (autoRotateSpeed != 0.f) {
        rotateAroundTarget(autoRotateSpeed,0.f);
        // sgRenderer->resetAccumulation();
        updateOSPRayCamera();
        update();
      }
      // accumulate, but only up to 32 frames
      if (sgRenderer->accumID < 32) {
        update();
      }
    }

    //! the QT callback that tells us that the image got resize
    void OSPRayRenderWidget::resize(int width, int height)
    {
      sgRenderer->frameBuffer = new sg::FrameBuffer(vec2i(width,height));
      sgRenderer->resetAccumulation();

      Ref<sg::PerspectiveCamera> camera = sgRenderer->camera.cast<sg::PerspectiveCamera>();
      camera->setAspect(width/float(height));
      camera->commit();
    }

    //! update the ospray camera (ospCamera) from the widget camera (this->camera)
    void OSPRayRenderWidget::updateOSPRayCamera()
    {
      if (!sgRenderer) return;
      if (!sgRenderer->camera) return;

      sgRenderer->resetAccumulation();
      Ref<sg::PerspectiveCamera> camera = sgRenderer->camera.cast<sg::PerspectiveCamera>();
      assert(camera);
      const vec3f from = frame->sourcePoint;
      const vec3f at   = frame->targetPoint;
      vec2i size = sgRenderer->frameBuffer->getSize();

      camera->setFrom(from);
      camera->setAt(at);
      camera->setUp(frame->orientation.vz);
      camera->setAspect(size.x/float(size.y));

      camera->commit();
    }

    //! create the lower-side time step slider (for models that have
    //! time steps; won't do anything for models that don't)
    void ModelViewer::createTimeSlider()
    {
    }

    //! create the widet on the side that'll host all the editing widgets
    void ModelViewer::createEditorWidgetStack()
    {
      editorWidgetStack = new EditorWidgetStack;
      editorWidgetDock = new QDockWidget(this);
      editorWidgetDock->setWindowTitle("Editors");
      editorWidgetDock->setWidget(editorWidgetStack);
      editorWidgetDock->setFeatures(0);
      addDockWidget(Qt::RightDockWidgetArea,editorWidgetDock);
    }

    void ModelViewer::createTransferFunctionEditor()
    {
      QWidget *xfEditorsPage = NULL;
      // make a list of all transfer function nodes in the scene graph
      std::vector<Ref<sg::TransferFunction> > xferFuncs;
      for (int i=0;i<sgRenderer->uniqueNodes.size();i++) {
        sg::TransferFunction *xf = dynamic_cast<sg::TransferFunction *>
          (sgRenderer->uniqueNodes.object[i]->node.ptr);
        if (xf) xferFuncs.push_back(xf);
<<<<<<< HEAD
=======
        // cout << "FOUND xf : " << xf << endl;
>>>>>>> 4630fcb4d1f8a05eec45d7b9dc251812d4f0f42c
      }
      std::cout << "#osp:qtv: found " << xferFuncs.size()
                << " transfer function nodes" << std::endl;
<commit_msg>conflict eliminated<commit_after>// ======================================================================== //
// 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 "ModelViewer.h"
#include "widgets/affineSpaceManipulator/HelperGeometry.h"
#include "FPSCounter.h"
// sg
#include "sg/SceneGraph.h"
#include "sg/Renderer.h"
// std
#include <sstream>

namespace ospray {
  namespace viewer {

    using std::cout;
    using std::endl;

    float autoRotateSpeed = 0.f;

    FPSCounter fps;

    OSPRayRenderWidget::OSPRayRenderWidget(Ref<sg::Renderer> renderer)
      : QAffineSpaceManipulator(QAffineSpaceManipulator::INSPECT),
        sgRenderer(renderer)
    {
      if (renderer->world) {
        box3f worldBounds = renderer->world->getBounds();
        if (!worldBounds.empty()) {
          float moveSpeed = .25*length(worldBounds.size());
          QAffineSpaceManipulator::setMoveSpeed(moveSpeed);
        }
      }
      Ref<sg::PerspectiveCamera> camera = renderer->camera.cast<sg::PerspectiveCamera>();
      if (camera) {
        frame->sourcePoint = camera->getFrom();
        frame->targetPoint = camera->getAt();
        frame->upVector    = camera->getUp();
        frame->orientation.vz = normalize(camera->getUp());
        frame->orientation.vy = normalize(camera->getAt() - camera->getFrom());
        frame->orientation.vx = normalize(cross(frame->orientation.vy,frame->orientation.vz));
      }
    }

    void OSPRayRenderWidget::setWorld(Ref<sg::World> world)
    {
      assert(sgRenderer);
      sgRenderer->setWorld(world);
      cout << "#ospQTV: world set, found "
           << sgRenderer->allNodes.size() << " nodes" << endl;
    }

    //! the QT callback that tells us that we have to redraw
    void OSPRayRenderWidget::redraw()
    {
      if (!sgRenderer) return;
      if (!sgRenderer->frameBuffer) return;
      if (!sgRenderer->camera) return;

      if (showFPS) {
        static int frameID = 0;
        if (frameID > 0) {
          fps.doneRender();
          printf("fps: %7.3f (smoothed: %7.3f)\n",fps.getFPS(),fps.getSmoothFPS());
        }
        fps.startRender();
        ++frameID;
      }

      sgRenderer->renderFrame();


      vec2i size = sgRenderer->frameBuffer->getSize();
      unsigned char *fbMem = sgRenderer->frameBuffer->map();
      glDrawPixels(size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, fbMem);
      sgRenderer->frameBuffer->unmap(fbMem);

      if (autoRotateSpeed != 0.f) {
        rotateAroundTarget(autoRotateSpeed,0.f);
        // sgRenderer->resetAccumulation();
        updateOSPRayCamera();
        update();
      }
      // accumulate, but only up to 32 frames
      if (sgRenderer->accumID < 32) {
        update();
      }
    }

    //! the QT callback that tells us that the image got resize
    void OSPRayRenderWidget::resize(int width, int height)
    {
      sgRenderer->frameBuffer = new sg::FrameBuffer(vec2i(width,height));
      sgRenderer->resetAccumulation();

      Ref<sg::PerspectiveCamera> camera = sgRenderer->camera.cast<sg::PerspectiveCamera>();
      camera->setAspect(width/float(height));
      camera->commit();
    }

    //! update the ospray camera (ospCamera) from the widget camera (this->camera)
    void OSPRayRenderWidget::updateOSPRayCamera()
    {
      if (!sgRenderer) return;
      if (!sgRenderer->camera) return;

      sgRenderer->resetAccumulation();
      Ref<sg::PerspectiveCamera> camera = sgRenderer->camera.cast<sg::PerspectiveCamera>();
      assert(camera);
      const vec3f from = frame->sourcePoint;
      const vec3f at   = frame->targetPoint;
      vec2i size = sgRenderer->frameBuffer->getSize();

      camera->setFrom(from);
      camera->setAt(at);
      camera->setUp(frame->orientation.vz);
      camera->setAspect(size.x/float(size.y));

      camera->commit();
    }

    //! create the lower-side time step slider (for models that have
    //! time steps; won't do anything for models that don't)
    void ModelViewer::createTimeSlider()
    {
    }

    //! create the widet on the side that'll host all the editing widgets
    void ModelViewer::createEditorWidgetStack()
    {
      editorWidgetStack = new EditorWidgetStack;
      editorWidgetDock = new QDockWidget(this);
      editorWidgetDock->setWindowTitle("Editors");
      editorWidgetDock->setWidget(editorWidgetStack);
      editorWidgetDock->setFeatures(0);
      addDockWidget(Qt::RightDockWidgetArea,editorWidgetDock);
    }

    void ModelViewer::createTransferFunctionEditor()
    {
      QWidget *xfEditorsPage = NULL;
      // make a list of all transfer function nodes in the scene graph
      std::vector<Ref<sg::TransferFunction> > xferFuncs;
      for (int i=0;i<sgRenderer->uniqueNodes.size();i++) {
        sg::TransferFunction *xf = dynamic_cast<sg::TransferFunction *>
          (sgRenderer->uniqueNodes.object[i]->node.ptr);
        if (xf) xferFuncs.push_back(xf);
      }
      std::cout << "#osp:qtv: found " << xferFuncs.size()
                << " transfer function nodes" << std::endl;

{'fraction_non_alphanumeric': 0.147927545691906, 'fraction_numerical': 0.007588120104438642, 'mean_word_length': 2.3489071038251366, 'pattern_counts': {'":': 0, '<': 76, '<?xml version=': 0, '>': 148, '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': '5422866', 'n_tokens_mistral': 3530, 'n_tokens_neox': 3334, 'n_words': 752}