Ejemplo n.º 1
0
	T pop(int stack_id)
	{
		int sp = stack_pointers[stack_id];
		if(sp < 0)
			std::abort();

		int bp = getBufferPointer(stack_id, sp);
		T data = buffer[bp];
		stack_pointers[stack_id] -= 1;
		return data;
	}
Ejemplo n.º 2
0
void ArnoldAnimationPatch::workerRender(FrameDeviceInfo frame) {
	std::stringstream ss;
	ss << "Received new frame: " << frame.time << "(" << frame.mode << ")";
	Logger::log(LDEBUG, ss.str());

	updateLight(frame.devices);
	bool success = ArnoldPatch::renderLoop(frame.devices);

#ifdef USE_ARNOLD
	// Dumps only when the image was rendered successfully for rendering.
	// If the worker was reset while rendering, doesn't dump.
	if (success && frame.mode == SimulationAnimationMode::RENDERING) {
		m_mem_frameManager->dump(frame.time, getBufferPointer(),
			getWidth(), getHeight());
		if (m_file_frameManager)
			m_file_frameManager->dump(frame.time, getBufferPointer(),
			getWidth(), getHeight());
	}
#endif
}
Ejemplo n.º 3
0
	void push(int stack_id, T data)
	{
		int sp = stack_pointers[stack_id];
		if(sp + 1 > stack_size)
			std::abort();

		sp += 1;
		int bp = getBufferPointer(stack_id, sp);
		buffer[bp] = data;
		stack_pointers[stack_id] = sp;
	}
TEST(DetectorSpectrumMapDataTest, create_message_buffer) {
  extern std::string testDataPath;
  auto detSpecMap =
      DetectorSpectrumMapData(testDataPath + "spectrum_gastubes_01.dat");

  std::string rawbuf;
  EXPECT_NO_THROW(detSpecMap.getBufferPointer(rawbuf));

  auto receivedMapData = DetectorSpectrumMapData();
  EXPECT_NO_THROW(receivedMapData.decodeMessage(
      reinterpret_cast<const uint8_t *>(rawbuf.c_str())));
  EXPECT_EQ(245768, receivedMapData.getNumberOfEntries());

  auto detectors = receivedMapData.getDetectors();
  EXPECT_EQ(1, detectors[0]);
  EXPECT_EQ(1100000, detectors[8]);
  EXPECT_EQ(4523511, detectors[245767]);

  auto spectra = receivedMapData.getSpectra();
  EXPECT_EQ(1, spectra[0]);
  EXPECT_EQ(9, spectra[8]);
  EXPECT_EQ(245768, spectra[245767]);
}
Ejemplo n.º 5
0
void ArnoldAnimationPatch::renderSingleFrameToBuffer(const set<Device*>& devices, unsigned char* buff, int w, int h) {
  if (m_mode != SimulationAnimationMode::STOPPED)
    disableContinuousRenderMode();

  FrameDeviceInfo frame;

  // Fulls time and mode for frame info.
  createFrameInfoHeader(frame);
  createFrameInfoBody(devices, frame, true);

  std::stringstream ss;
  ss << "Rendering single frame: " << frame.time;
  Logger::log(LDEBUG, ss.str());

  // Interrupts the current rendering if in the interactive mode.
  if (m_mode == SimulationAnimationMode::INTERACTIVE ||
    m_mode == SimulationAnimationMode::RECORDING) {
    interruptRender();
  }

  // Render immediately.
  if (!m_interface->isDistributedOpen()) {
	  m_interface->init(this->toJSON());

	  // Check if we were able to open a connection
	  if (!m_interface->isDistributedOpen()) {
		  std::cerr << "Connection could not be established. " <<
			  "Check to make sure your host and port " <<
			  "parameters are correct and that nobody " <<
			  "else is currently using the remote renderer" << std::endl;

		  return;
	  }
  }

  bool success = false;
  float* bp = nullptr;
  int cid;

  if (CachingArnoldInterface* ci = dynamic_cast<CachingArnoldInterface*>(m_interface)) {
#ifdef USE_ARNOLD
    success = ci->render(devices, w, h, cid) == AI_SUCCESS;
#else
    success = ci->render(devices, w, h, cid) == 0;
#endif
    // we need to pull the proper buffer from the right context
    bp = ci->getBufferForContext(cid);
    frame.clear();
  }
  else {
    updateLight(devices);
    success = ArnoldPatch::renderLoop(devices);
    frame.clear();
    bp = getBufferPointer();
  }

  if (success) {
    for (int j = 0; j < h; j++) {
      for (int i = 0; i < w; i++) {
        int offset = (j * w + i) * 4;

        // convert to bytes
        buff[offset] = static_cast<unsigned char>(bp[offset + 2] * 0xff);
        buff[offset + 1] = static_cast<unsigned char>(bp[offset + 1] * 0xff);
        buff[offset + 2] = static_cast<unsigned char>(bp[offset + 0] * 0xff);
        buff[offset + 3] = static_cast<unsigned char>(bp[offset + 3] * 0xff);
      }
    }
  }

  if (CachingArnoldInterface* ci = dynamic_cast<CachingArnoldInterface*>(m_interface)) {
    ci->closeContext(cid);
  }
}
Ejemplo n.º 6
0
void ArnoldAnimationPatch::renderSingleFrame(const set<Device*>& devices, string basepath, string filename) {
  if (m_mode != SimulationAnimationMode::STOPPED)
    disableContinuousRenderMode();

  FrameDeviceInfo frame;

  // Fulls time and mode for frame info.
  createFrameInfoHeader(frame);
  createFrameInfoBody(devices, frame);

  std::stringstream ss;
  ss << "Rendering single frame: " << frame.time;
  Logger::log(LDEBUG, ss.str());

  // Interrupts the current rendering if in the interactive mode.
  if (m_mode == SimulationAnimationMode::INTERACTIVE ||
    m_mode == SimulationAnimationMode::RECORDING) {
    interruptRender();
  }

  // Render immediately.
  if (!m_interface->isDistributedOpen()) {
	  m_interface->init(this->toJSON());
	  
	  // Check if we were able to open a connection
	  if (!m_interface->isDistributedOpen()) {
		  std::cerr << "Connection could not be established. " << 
			  "Check to make sure your host and port " << 
			  "parameters are correct and that nobody " << 
			  "else is currently using the remote renderer" << std::endl;

		  return;
	  }
  }

  bool success = false;
  float* bp = nullptr;
  int cid;
  int w = getWidth();
  int h = getHeight();

  if (CachingArnoldInterface* ci = dynamic_cast<CachingArnoldInterface*>(m_interface)) {
#ifdef USE_ARNOLD
    success = ci->render(devices, w, h, cid) == AI_SUCCESS;
#else
    success = ci->render(devices, w, h, cid) == 0;
#endif
    // we need to pull the proper buffer from the right context
    bp = ci->getBufferForContext(cid);
    frame.clear();
  }
  else {
    updateLight(devices);
    success = ArnoldPatch::renderLoop(devices);
    frame.clear();
    bp = getBufferPointer();
  }

  if (success) {
    unsigned char *bytes = new unsigned char[w * h * 4];
    floats_to_bytes(bytes, bp, w, h);

    string file = basepath + "/" + filename + ".png";

    if (!imageio_save_image(file.c_str(), bytes, getWidth(), getHeight())) {
      std::stringstream err_ss;
      err_ss << "Error to write png: " << filename;
      Logger::log(ERR, err_ss.str());
    }
  }

  if (CachingArnoldInterface* ci = dynamic_cast<CachingArnoldInterface*>(m_interface)) {
    ci->closeContext(cid);
  }
}
bool khclient_rpc_init(void)
{
   workspace = NULL;
   ipc = (IPC_shared_mem_t*)getBufferPointer();
   return true;
}