Exemplo n.º 1
0
Arquivo: main.cpp Projeto: beneon/MITK
void extenderPattern()
{
  //! [2]
  // Get all loaded modules
  std::vector<Module*> modules;
  ModuleRegistry::GetLoadedModules(modules);

  // Check if a module defines a "service-component" property
  // and use its value to retrieve an embedded resource containing
  // a component description.
  for(std::size_t i = 0; i < modules.size(); ++i)
  {
    Module* const module = modules[i];
    std::string componentPath = module->GetProperty("service-component");
    if (!componentPath.empty())
    {
      ModuleResource componentResource = module->GetResource(componentPath);
      if (!componentResource.IsValid() || componentResource.IsDir()) continue;

      // Create a std::istream compatible object and parse the
      // component description.
      ModuleResourceStream resStream(componentResource);
      parseComponentDefinition(resStream);
    }
  }
  //! [2]
}
void ShellService::LoadSchemeResource(const BundleResource& res)
{
  std::cout << "Reading " << res.GetResourcePath();
  BundleResourceStream resStream(res);
  int resBufLen = res.GetSize() + 1;
  char* resBuf = new char[resBufLen];
  resStream.read(resBuf, resBufLen);
  if (resStream.eof() || resStream.good())
  {
    resBuf[static_cast<std::size_t>(resStream.gcount())] = '\0';
    scheme_load_string(d->m_Scheme, resBuf);
  }
  else
  {
    std::cerr << "Could not read " << res.GetResourcePath() << " file from resource";
  }
  delete[] resBuf;
}
mitk::CameraIntrinsics::Pointer mitk::AbstractToFDeviceFactory::GetCameraIntrinsics()
{
  us::ModuleResource resource = GetIntrinsicsResource();
  if (! resource.IsValid())
  {
    MITK_WARN << "Could not load resource '" << resource.GetName() << "'. CameraIntrinsics are invalid!";
  }

  // Create ResourceStream from Resource
  us::ModuleResourceStream resStream(resource);

  // Parse XML
  TiXmlDocument xmlDocument;
  resStream >> xmlDocument;

  //Retrieve Child Element and convert to CamerIntrinsics
  TiXmlElement* element = xmlDocument.FirstChildElement();
  mitk::CameraIntrinsics::Pointer intrinsics = mitk::CameraIntrinsics::New();
  intrinsics->FromXML(element);

  return intrinsics;
}
Exemplo n.º 4
0
void GfxCursor32::setView(const GuiResourceId viewId, const int16 loopNo, const int16 celNo) {
    hide();

    _cursorInfo.resourceId = viewId;
    _cursorInfo.loopNo = loopNo;
    _cursorInfo.celNo = celNo;

    if (_macCursorRemap.empty() && viewId != -1) {
        CelObjView view(viewId, loopNo, celNo);

        _hotSpot = view._displace;
        _width = view._width;
        _height = view._height;

        // SSCI never increased the size of cursors, but some of the cursors
        // in early SCI32 games were designed for low-resolution display mode
        // and so are kind of hard to pick out when running in high-resolution
        // mode.
        // To address this, we make some slight adjustments to cursor display
        // in these early games:
        // GK1: All the cursors are increased in size since they all appear to
        //      be designed for low-res display.
        // PQ4: We only make the cursors bigger if they are above a set
        //      threshold size because inventory items usually have a
        //      high-resolution cursor representation.
        bool pixelDouble = false;
        if (g_sci->_gfxFrameout->_isHiRes &&
                (g_sci->getGameId() == GID_GK1 ||
                 (g_sci->getGameId() == GID_PQ4 && _width <= 22 && _height <= 22))) {

            _width *= 2;
            _height *= 2;
            _hotSpot.x *= 2;
            _hotSpot.y *= 2;
            pixelDouble = true;
        }

        _cursor.data = (byte *)realloc(_cursor.data, _width * _height);
        _cursor.rect = Common::Rect(_width, _height);
        memset(_cursor.data, 255, _width * _height);
        _cursor.skipColor = 255;

        Buffer target(_width, _height, _cursor.data);
        if (pixelDouble) {
            view.draw(target, _cursor.rect, Common::Point(0, 0), false, 2, 2);
        } else {
            view.draw(target, _cursor.rect, Common::Point(0, 0), false);
        }
    } else if (!_macCursorRemap.empty() && viewId != -1) {
        // Mac cursor handling
        GuiResourceId viewNum = viewId;

        // Remap cursor view based on what the scripts have given us.
        for (uint32 i = 0; i < _macCursorRemap.size(); i++) {
            if (viewNum == _macCursorRemap[i]) {
                viewNum = (i + 1) * 0x100 + loopNo * 0x10 + celNo;
                break;
            }

            if (i == _macCursorRemap.size())
                error("Unmatched Mac cursor %d", viewNum);
        }

        _cursorInfo.resourceId = viewNum;

        Resource *resource = g_sci->getResMan()->findResource(ResourceId(kResourceTypeCursor, viewNum), false);

        if (!resource) {
            // The cursor resources often don't exist, this is normal behavior
            debug(0, "Mac cursor %d not found", viewNum);
            return;
        }
        Common::MemoryReadStream resStream(resource->data, resource->size);
        Graphics::MacCursor *macCursor = new Graphics::MacCursor();

        if (!macCursor->readFromStream(resStream)) {
            warning("Failed to load Mac cursor %d", viewNum);
            delete macCursor;
            return;
        }

        _hotSpot = Common::Point(macCursor->getHotspotX(), macCursor->getHotspotY());
        _width = macCursor->getWidth();
        _height = macCursor->getHeight();

        _cursor.data = (byte *)realloc(_cursor.data, _width * _height);
        memcpy(_cursor.data, macCursor->getSurface(), _width * _height);
        _cursor.rect = Common::Rect(_width, _height);
        _cursor.skipColor = macCursor->getKeyColor();

        // The cursor will be drawn on next refresh
        delete macCursor;
    } else {
        _hotSpot = Common::Point(0, 0);
        _width = _height = 1;
        _cursor.data = (byte *)realloc(_cursor.data, _width * _height);
        _cursor.rect = Common::Rect(_width, _height);
        *_cursor.data = _cursor.skipColor;
        _cursorBack.rect = _cursor.rect;
        _cursorBack.rect.clip(_vmapRegion.rect);
        if (!_cursorBack.rect.isEmpty()) {
            readVideo(_cursorBack);
        }
    }

    _cursorBack.data = (byte *)realloc(_cursorBack.data, _width * _height);
    _drawBuff1.data = (byte *)realloc(_drawBuff1.data, _width * _height);
    _drawBuff2.data = (byte *)realloc(_drawBuff2.data, _width * _height * 4);
    _savedVmapRegion.data = (byte *)realloc(_savedVmapRegion.data, _width * _height);

    unhide();
}
void mitk::TrackingVolumeGenerator::GenerateData()
{
  mitk::Surface::Pointer output = this->GetOutput();  //the surface wich represents the tracking volume

  std::string filepath = ""; // Full path to file (wil be resolved later)
  std::string filename = this->m_Data.VolumeModelLocation; // Name of the file or possibly a magic String, e.g. "cube"

  MITK_INFO << "volume: " << filename;

  // See if filename matches a magic string.
  if (filename.compare("cube") == 0){
    vtkSmartPointer<vtkCubeSource> cubeSource = vtkSmartPointer<vtkCubeSource>::New();
    double bounds[6];
    bounds[0] = bounds[2] = bounds[4] = -400.0;  // initialize bounds to -400 ... +400 cube. This is the default value of the
    bounds[1] = bounds[3] = bounds[5] =  400.0;  // virtual tracking device, but it can be changed. In that case,
    // the tracking volume polydata has to be updated manually
    cubeSource->SetBounds(bounds);
    cubeSource->Update();

    output->SetVtkPolyData(cubeSource->GetOutput()); //set the vtkCubeSource as polyData of the surface
    return;
  }
  if (filename.compare("") == 0) // empty String means no model, return empty output
  {
    output->SetVtkPolyData(vtkPolyData::New()); //initialize with empty poly data (otherwise old surfaces may be returned) => so an empty surface is returned
    return;
  }

  // from here on, we assume that filename contains an actual filename and not a magic string

  us::Module* module = us::GetModuleContext()->GetModule();

  us::ModuleResource moduleResource = module->GetResource(filename);
  bool isCompressed = moduleResource.IsCompressed();

  // Create ResourceStream from Resource
  us::ModuleResourceStream resStream(moduleResource,std::ios_base::binary);

  ofstream tmpOutputStream;
  std::string tmpFilePath = mitk::IOUtil::CreateTemporaryFile(tmpOutputStream);
  if (!isCompressed)
  {
    tmpOutputStream << resStream.rdbuf();
  }
  else
  {
    resStream.seekg(0, std::ios::end);
    std::ios::pos_type length = resStream.tellg();
    resStream.seekg(0, std::ios::beg);

    char* data = new char[length];
    resStream.read(data, length);
    tmpOutputStream.close();
    tmpOutputStream.open(tmpFilePath.c_str(), std::ios_base::binary | std::ios_base::out);
    tmpOutputStream.write(data, length);
    tmpOutputStream.flush();
    delete[] data;
  }
  tmpOutputStream.close();


  //filepath = mitk::StandardFileLocations::GetInstance()->FindFile(filename.c_str());

  if (tmpFilePath.empty())
  {
    MITK_ERROR << ("Volume Generator could not find the specified file " + filename);
    return;
  }

  mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New();
  stlReader->SetFileName( tmpFilePath.c_str() );
  stlReader->Update();

  std::remove(tmpFilePath.c_str());

  if ( stlReader->GetOutput() == NULL)
  {
    MITK_ERROR << "Error while reading file";
    return ;
  }
  output->SetVtkPolyData( stlReader->GetOutput()->GetVtkPolyData());//set the visible trackingvolume
}