<commit_before>//****************************************************************************
// Project:         Virvo (Virtual Reality Volume Renderer)
// Copyright:       (c) 1999-2004 <NAME>. All rights reserved.
// Author's E-Mail: <EMAIL>
// Affiliation:     Brown University, Department of Computer Science
//****************************************************************************

#include <iostream>
#include <iomanip>
using std::cerr;
using std::endl;
using std::ios;

#include <stdlib.h>
#include <stdio.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <time.h>
#include <assert.h>
#include <math.h>

#ifdef WIN32
#ifndef HLRS
#include <winsock2.h>
#endif
#include <windows.h>
#else
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif

#ifdef VV_DEBUG_MEMORY
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
#endif

#include "../src/vvvirvo.h"
#include "../src/vvgltools.h"
#include "../src/vvoffscreenbuffer.h"
#include "../src/vvprintgl.h"
#include "../src/vvstopwatch.h"
#include "../src/vvrendercontext.h"
#include "../src/vvrenderer.h"
#include "../src/vvfileio.h"
#include "../src/vvdebugmsg.h"
#include "../src/vvsocketio.h"
#include "../src/vvtexrend.h"
#include "vvobjview.h"
#include "vvperformancetest.h"
#include "vvview.h"

const int vvView::ROT_TIMER_DELAY = 20;
const int vvView::DEFAULTSIZE = 512;
const float vvView::OBJ_SIZE  = 1.0f;
const int vvView::DEFAULT_PORT = 31050;
vvView* vvView::ds = NULL;

//#define CLIPPING_TEST

//----------------------------------------------------------------------------
/// Constructor
vvView::vvView()
{
   lastWidth = lastHeight = DEFAULTSIZE;
   winWidth = winHeight = DEFAULTSIZE;
   lastPosX = lastPosY = 50;
   pressedButton = NO_BUTTON;
   ds = this;
   renderer = NULL;
   vd = NULL;
   ov = NULL;
   currentGeom = vvTexRend::VV_AUTO;              // vvTexRend::VV_SLICES;
   currentVoxels = vvTexRend::VV_BEST;            // vvTexRend::VV_RGBA;
   bgColor[0] = bgColor[1] = bgColor[2] = 0.0f;
   frame = 0;
   filename = NULL;
   window = 0;
   draftQuality = 1.0f;
   highQuality = 5.0f;
   onOff[0] = "off";
   onOff[1] = "on";
   pos.zero();
   numDisplays = 0;
   displayNames = NULL;
   animating             = false;
   rotating              = false;
   activeStereoCapable   = false;
   boundariesMode        = false;
   orientationMode       = false;
   fpsMode               = false;
   stereoMode            = 0;
   fullscreenMode        = false;
   interpolMode          = true;
   preintMode            = false;
   paletteMode           = false;
   emptySpaceLeapingMode = true;
   perspectiveMode       = true;
   timingMode            = false;
   opCorrMode            = true;
   gammaMode             = false;
   mipMode               = 0;
   rotationMode          = false;
   refinement            = false;
   hqMode                = false;
   animSpeed             = 1.0f;
   iconMode              = false;
   gpuproxygeo           = true;
   useOffscreenBuffer    = false;
   bufferPrecision       = 8;
   useHeadLight          = false;
   slaveMode             = false;
   sio                   = NULL;
   remoteRendering       = true;
   clipBuffer            = NULL;
   framebufferDump       = NULL;
   offscreenBuffer       = NULL;
   redistributeVolData   = false;
   allFileNamesAreEqual  = false;
}


//----------------------------------------------------------------------------
/// Destructor.
vvView::~vvView()
{
   delete renderer;
   delete ov;
   delete vd;
   delete sio;
   delete offscreenBuffer;
}


//----------------------------------------------------------------------------
/** VView main loop.
  @param filename  volume file to display
*/
void vvView::mainLoop(int argc, char *argv[])
{
   vvDebugMsg::msg(0, "vvView::mainLoop()");

   if (slaveMode)
   {
      cerr << "Renderer started in slave mode" << endl;

      sio = new vvSocketIO(vvView::DEFAULT_PORT , vvSocket::VV_TCP);
      sio->set_debuglevel(vvDebugMsg::getDebugLevel());
      sio->init();
      sio->no_nagle();

      bool loadVolumeFromFile;
      sio->getBool(loadVolumeFromFile);

      if (loadVolumeFromFile)
      {
         char* fn = 0;
         sio->getFileName(fn);
         cerr << "Load volume from file: " << fn << endl;
         vd = new vvVolDesc(fn);

         vvFileIO* fio = new vvFileIO();
         if (fio->loadVolumeData(vd) != vvFileIO::OK)<commit_msg>Die gracefully if no socket connection could be established<commit_after>//****************************************************************************
// Project:         Virvo (Virtual Reality Volume Renderer)
// Copyright:       (c) 1999-2004 <NAME>. All rights reserved.
// Author's E-Mail: <EMAIL>
// Affiliation:     Brown University, Department of Computer Science
//****************************************************************************

#include <iostream>
#include <iomanip>
using std::cerr;
using std::endl;
using std::ios;

#include <stdlib.h>
#include <stdio.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <time.h>
#include <assert.h>
#include <math.h>

#ifdef WIN32
#ifndef HLRS
#include <winsock2.h>
#endif
#include <windows.h>
#else
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif

#ifdef VV_DEBUG_MEMORY
#include <crtdbg.h>
#define new new(_NORMAL_BLOCK,__FILE__, __LINE__)
#endif

#include "../src/vvvirvo.h"
#include "../src/vvgltools.h"
#include "../src/vvoffscreenbuffer.h"
#include "../src/vvprintgl.h"
#include "../src/vvstopwatch.h"
#include "../src/vvrendercontext.h"
#include "../src/vvrenderer.h"
#include "../src/vvfileio.h"
#include "../src/vvdebugmsg.h"
#include "../src/vvsocketio.h"
#include "../src/vvtexrend.h"
#include "vvobjview.h"
#include "vvperformancetest.h"
#include "vvview.h"

const int vvView::ROT_TIMER_DELAY = 20;
const int vvView::DEFAULTSIZE = 512;
const float vvView::OBJ_SIZE  = 1.0f;
const int vvView::DEFAULT_PORT = 31050;
vvView* vvView::ds = NULL;

//#define CLIPPING_TEST

//----------------------------------------------------------------------------
/// Constructor
vvView::vvView()
{
   lastWidth = lastHeight = DEFAULTSIZE;
   winWidth = winHeight = DEFAULTSIZE;
   lastPosX = lastPosY = 50;
   pressedButton = NO_BUTTON;
   ds = this;
   renderer = NULL;
   vd = NULL;
   ov = NULL;
   currentGeom = vvTexRend::VV_AUTO;              // vvTexRend::VV_SLICES;
   currentVoxels = vvTexRend::VV_BEST;            // vvTexRend::VV_RGBA;
   bgColor[0] = bgColor[1] = bgColor[2] = 0.0f;
   frame = 0;
   filename = NULL;
   window = 0;
   draftQuality = 1.0f;
   highQuality = 5.0f;
   onOff[0] = "off";
   onOff[1] = "on";
   pos.zero();
   numDisplays = 0;
   displayNames = NULL;
   animating             = false;
   rotating              = false;
   activeStereoCapable   = false;
   boundariesMode        = false;
   orientationMode       = false;
   fpsMode               = false;
   stereoMode            = 0;
   fullscreenMode        = false;
   interpolMode          = true;
   preintMode            = false;
   paletteMode           = false;
   emptySpaceLeapingMode = true;
   perspectiveMode       = true;
   timingMode            = false;
   opCorrMode            = true;
   gammaMode             = false;
   mipMode               = 0;
   rotationMode          = false;
   refinement            = false;
   hqMode                = false;
   animSpeed             = 1.0f;
   iconMode              = false;
   gpuproxygeo           = true;
   useOffscreenBuffer    = false;
   bufferPrecision       = 8;
   useHeadLight          = false;
   slaveMode             = false;
   sio                   = NULL;
   remoteRendering       = true;
   clipBuffer            = NULL;
   framebufferDump       = NULL;
   offscreenBuffer       = NULL;
   redistributeVolData   = false;
   allFileNamesAreEqual  = false;
}


//----------------------------------------------------------------------------
/// Destructor.
vvView::~vvView()
{
   delete renderer;
   delete ov;
   delete vd;
   delete sio;
   delete offscreenBuffer;
}


//----------------------------------------------------------------------------
/** VView main loop.
  @param filename  volume file to display
*/
void vvView::mainLoop(int argc, char *argv[])
{
   vvDebugMsg::msg(0, "vvView::mainLoop()");

   if (slaveMode)
   {
      cerr << "Renderer started in slave mode" << endl;

      sio = new vvSocketIO(vvView::DEFAULT_PORT , vvSocket::VV_TCP);
      sio->set_debuglevel(vvDebugMsg::getDebugLevel());
      if (sio->init() != vvSocket::VV_OK)
      {
        // TODO: Evaluate the error type, maybe don't even return but try again.
        cerr << "Couldn't initialize the socket connection" << endl;
        cerr << "Exiting..." << endl;
        return;
      }
      sio->no_nagle();

      bool loadVolumeFromFile;
      sio->getBool(loadVolumeFromFile);

      if (loadVolumeFromFile)
      {
         char* fn = 0;
         sio->getFileName(fn);
         cerr << "Load volume from file: " << fn << endl;
         vd = new vvVolDesc(fn);

         vvFileIO* fio = new vvFileIO();
         if (fio->loadVolumeData(vd) != vvFileIO::OK)
{'fraction_non_alphanumeric': 0.20329370705638564, 'fraction_numerical': 0.010033809575744356, 'mean_word_length': 2.106368563685637, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2844193', 'n_tokens_mistral': 3035, 'n_tokens_neox': 2914, 'n_words': 662}