示例#1
0
void PionPlugin::openFile(const std::string& plugin_file)
{
	releaseData();	// make sure we're not already pointing to something
	
	// use a temporary object first since openPlugin() may throw
	PionPluginData plugin_data(getPluginName(plugin_file));
	
	// check to see if we already have a matching shared library
	boost::mutex::scoped_lock plugin_lock(m_plugin_mutex);
	PluginMap::iterator itr = m_plugin_map.find(plugin_data.m_plugin_name);
	if (itr == m_plugin_map.end()) {
		// no plug-ins found with the same name
		
		// open up the shared library using our temporary data object
		openPlugin(plugin_file, plugin_data);	// may throw
		
		// all is good -> insert it into the plug-in map
		m_plugin_data = new PionPluginData(plugin_data);
		m_plugin_map.insert( std::make_pair(m_plugin_data->m_plugin_name,
											m_plugin_data) );
	} else {
		// found an existing plug-in with the same name
		m_plugin_data = itr->second;
	}
	
	// increment the number of references
	++ m_plugin_data->m_references;
}
示例#2
0
void PionPlugin::openStaticLinked(const std::string& plugin_name,
								  void *create_func,
								  void *destroy_func)
{
	releaseData();	// make sure we're not already pointing to something

	// check to see if we already have a matching shared library
	boost::mutex::scoped_lock plugin_lock(m_plugin_mutex);
	PluginMap::iterator itr = m_plugin_map.find(plugin_name);
	if (itr == m_plugin_map.end()) {
		// no plug-ins found with the same name

		// all is good -> insert it into the plug-in map
		m_plugin_data = new PionPluginData(plugin_name);
		m_plugin_data->m_lib_handle = NULL; // this will indicate that we are using statically linked plug-in
		m_plugin_data->m_create_func = create_func;
		m_plugin_data->m_destroy_func = destroy_func;
		m_plugin_map.insert(std::make_pair(m_plugin_data->m_plugin_name,
										   m_plugin_data));
	} else {
		// found an existing plug-in with the same name
		m_plugin_data = itr->second;
	}

	// increment the number of references
	++ m_plugin_data->m_references;
}
示例#3
0
AlgorithmStatus SilenceRate::process() {
  EXEC_DEBUG("process()");

  AlgorithmStatus status = acquireData();

  if (status != OK) return status;

  const vector<Real>& frame = _frame.firstToken();

  if (frame.empty()) {
    throw EssentiaException("SilenceRate: a given input frame was empty, "
                            "cannot compute the power of an empty frame.");
  }

  Real power = instantPower(frame);

  for (int i=0; i<(int)_outputs.size(); i++) {
    Real& output = _outputs[i]->firstToken();
    output = power < _thresholds[i]? 1.0 : 0.0;
  }

  releaseData();

  return OK;
}
示例#4
0
AlgorithmStatus NearestNeighbor::process() {

  AlgorithmStatus status = acquireData();

  if (status != OK) {
	// if shouldStop is true, that means there is no more audio coming
    if (!shouldStop()) return status;
    return NO_INPUT;
  }


  vector<Real> input = _sample.lastTokenProduced();
  vector<int>& output = _label.tokens();

  Real bestDist = -1;
  int bestLabel = -1;
  Real curDist;
  for (unsigned int i = 0; i < _vocab.size(); i++) {
    curDist = getDistance(input, _vocab[i]);
    if (curDist < bestDist || bestDist < 0) {
	  bestDist = curDist;
      bestLabel = i;
    }
  }
  if (bestLabel > 0) {
	output.push_back(bestLabel); 
  }
  else {
    throw EssentiaException("NearestNeighbor: No label was ever chosen");
  }

  releaseData();

  return OK;
}
示例#5
0
void DevState::releaseAll() {
	ods("D3D9: Release All");
	releaseData();
	if (pSB)
		pSB->Release();
	pSB = NULL;
}
示例#6
0
void Config::_deregisterData()
{
    releaseData();
    deregisterObject( &_frameData );

    _initData.setFrameDataID( eq::UUID::ZERO );
}
示例#7
0
void StringData::append(const char *s, int len) {
  if (len == 0) return;

  if (len < 0 || (len & IsMask)) {
    throw InvalidArgumentException("len: %d", len);
  }

  ASSERT(!isStatic()); // never mess around with static strings!

  if (!isMalloced()) {
    int newlen;
    m_data = string_concat(data(), size(), s, len, newlen);
    if (isShared()) {
      m_shared->decRef();
    }
    m_len = newlen;
    m_hash = 0;
  } else if (m_data == s) {
    int newlen;
    char *newdata = string_concat(data(), size(), s, len, newlen);
    releaseData();
    m_data = newdata;
    m_len = newlen;
  } else {
    int dataLen = size();
    ASSERT((m_data > s && m_data - s > len) ||
           (m_data < s && s - m_data > dataLen)); // no overlapping
    m_len = len + dataLen;
    m_data = (const char*)realloc((void*)m_data, m_len + 1);
    memcpy((void*)(m_data + dataLen), s, len);
    ((char*)m_data)[m_len] = '\0';
    m_hash = 0;
  }
}
	virtual void addCVImageBuffer(CVImageBufferRef in_ref)
	{
		if (in_ref)	CVPixelBufferRetain(in_ref);
		releaseData();
		
		m_ref = in_ref;
	}
AlgorithmStatus OverlapAdd::process() {
  EXEC_DEBUG("process()");
  AlgorithmStatus status = acquireData();
  EXEC_DEBUG("data acquired");

  if (status != OK) {
    if (!shouldStop()) return status;

    int available = input("frame").available();
    if (available == 0) {
      return FINISHED;
    }
    // otherwise, there are still some frames
    return CONTINUE;
  }

  const vector<vector<Real> >& frames = _frames.tokens();
  vector<Real>& output = _output.tokens();

  assert(frames.size() == 1 && (int) output.size() == _hopSize);
  const vector<Real> & windowedFrame = frames[0];

  if (windowedFrame.empty()) throw EssentiaException("OverlapAdd: the input frame is empty");

  processFrame(_tmpFrame, windowedFrame, output, _frameHistory, _frameSize,
               _hopSize, _normalizationGain);

  EXEC_DEBUG("releasing");
  releaseData();
  EXEC_DEBUG("released");

  return OK;
}
示例#10
0
AlgorithmStatus CvShow::process() {

  AlgorithmStatus status = acquireData();
  
  if (status != OK) {
    return status;
  }
  
  cout << "CvShow OK" << endl;
  Mat frame = _frame.firstToken();

  if (_width >= 1 && _height >= 1) {
    resize(frame, resized, resized.size(), 0, 0, INTER_LINEAR);
    imshow(_window_name, resized);
  }
  else {
	imshow(_window_name, frame);
  }
  
  cout << _wait << endl;
  waitKey(_wait);
  
  releaseData();

  return OK;
}
示例#11
0
文件: Image.cpp 项目: rottaca/FreeCV
Image& Image::operator=(const Image& img)
{
	releaseData();
	if(img.isValid())
		init(img.getWidth(),img.getHeight(),img.getFormat(),img.getPtr<unsigned char>(),true);

	return *this;
}
示例#12
0
//! (internal)
void StringData::setData(Data * newData){
	if(newData!=data){
		if(--data->referenceCounter <=0 )
			releaseData(data);
		++newData->referenceCounter;
		data = newData;
	}
}
示例#13
0
void PionPlugin::grabData(const PionPlugin& p)
{
	releaseData();	// make sure we're not already pointing to something
	boost::mutex::scoped_lock plugin_lock(m_plugin_mutex);
	m_plugin_data = const_cast<PionPluginData*>(p.m_plugin_data);
	if (m_plugin_data != NULL) {
		++ m_plugin_data->m_references;
	}
}
示例#14
0
void StringData::attach(char *data, int len) {
  if (uint32_t(len) > MaxSize) {
    throw InvalidArgumentException("len>=2^30", len);
  }
  releaseData();
  m_len = len;
  m_data = data;
  m_big.cap = len | IsMalloc;
}
示例#15
0
void StringData::assign(SharedVariant *shared) {
  ASSERT(shared);
  releaseData();
  shared->incRef();
  m_shared = shared;
  m_data = m_shared->stringData();
  m_len = m_shared->stringLength() | IsShared;
  ASSERT(m_data);
}
示例#16
0
//-------------------------------------------------------------------------------------------------------------
void Mesh::InitData(){
    releaseData();

    NumNormals = NumCoordinates = NumVerts;
    //AddPosition = AddNormal = AddCoordinate = 0;
    Vertices = new Vector3s[NumVerts];
    Normals = new Vector3s[NumNormals];
    UV = new Vector2s[NumCoordinates];
    Faces = new ITriangle[NumFaces];
}
示例#17
0
HRESULT BinaryDumpReader::createFirstConnected()
{
	std::string filename = GlobalAppState::getInstance().s_BinaryDumpReaderSourceFile;
	std::cout << "Start loading binary dump" << std::endl;
	//BinaryDataStreamZLibFile inputStream(filename, false);
	BinaryDataStreamFile inputStream(filename, false);
	CalibratedSensorData sensorData;
	inputStream >> sensorData;
	std::cout << "Loading finished" << std::endl;
	std::cout << sensorData << std::endl;

	DepthSensor::init(sensorData.m_DepthImageWidth, sensorData.m_DepthImageHeight, std::max(sensorData.m_ColorImageWidth,1u), std::max(sensorData.m_ColorImageHeight,1u));
	mat4f intrinsics(sensorData.m_CalibrationDepth.m_Intrinsic);
	initializeIntrinsics(sensorData.m_CalibrationDepth.m_Intrinsic(0,0), sensorData.m_CalibrationDepth.m_Intrinsic(1,1), sensorData.m_CalibrationDepth.m_Intrinsic(0,2), sensorData.m_CalibrationDepth.m_Intrinsic(1,2));

	m_NumFrames = sensorData.m_DepthNumFrames;
	assert(sensorData.m_ColorNumFrames == sensorData.m_DepthNumFrames || sensorData.m_ColorNumFrames == 0);		
	releaseData();
	m_DepthD16Array = new USHORT*[m_NumFrames];
	for (unsigned int i = 0; i < m_NumFrames; i++) {
		m_DepthD16Array[i] = new USHORT[getDepthWidth()*getDepthHeight()];
		for (unsigned int k = 0; k < getDepthWidth()*getDepthHeight(); k++) {
			m_DepthD16Array[i][k] = (USHORT)(sensorData.m_DepthImages[i][k]*1000.0f + 0.5f);
		}
	}

	std::cout << "loading depth done" << std::endl;
	if (sensorData.m_ColorImages.size() > 0) {
		m_bHasColorData = true;
		m_ColorRGBXArray = new BYTE*[m_NumFrames];
		for (unsigned int i = 0; i < m_NumFrames; i++) {
			m_ColorRGBXArray[i] = new BYTE[getColorWidth()*getColorHeight()*getColorBytesPerPixel()];
			for (unsigned int k = 0; k < getColorWidth()*getColorHeight(); k++) {
				const BYTE* c = (BYTE*)&(sensorData.m_ColorImages[i][k]); 
				m_ColorRGBXArray[i][k*getColorBytesPerPixel()+0] = c[0];
				m_ColorRGBXArray[i][k*getColorBytesPerPixel()+1] = c[1];
				m_ColorRGBXArray[i][k*getColorBytesPerPixel()+2] = c[2];
				m_ColorRGBXArray[i][k*getColorBytesPerPixel()+3] = 255;
				//I don't know really why this has to be swapped...
			}
			//std::string outFile = "colorout//color" + std::to_string(i) + ".png";
			//ColorImageR8G8B8A8 image(getColorHeight(), getColorWidth(), (vec4uc*)m_ColorRGBXArray[i]);
			//FreeImageWrapper::saveImage(outFile, image);
		}
	} else {
		m_bHasColorData = false;
	}
	sensorData.deleteData();

	std::cout << "loading color done" << std::endl;


	return S_OK;
}
示例#18
0
AlgorithmStatus AccumulatorAlgorithm::process() {
  EXEC_DEBUG("process()");
  AlgorithmStatus status = acquireData();

  if (status == OK) {
    consume();
    releaseData();

    return OK;
  }

  // status != SYNC_OK: we couldn't acquire a sufficient number of tokens...

  // if we're not yet at the end of the stream, just return and wait for more
  if (!shouldStop()) return status; // most likely NO_INPUT


  // we are at the end of the stream, we need to work with what's available
  int available = _inputStream->available();
  EXEC_DEBUG("EOS; there are " << available << " available tokens left");

  if (available > 0) {
    _inputStream->setAcquireSize(available);
    _inputStream->setReleaseSize(available);

    status = acquireData();
    if (status != OK) {
      throw EssentiaException("Accumulator EOS internal scheduling error...");
    }

    // consume our very last tokens
    consume();
    releaseData();
  }

  // and now the big moment we've been waiting for all the time! All the tokens
  // from the input stream have been consumed, it is time to output our final result
  finalProduce();

  return FINISHED; // yes we produced something, and we're done!
}
//This function is not access directly because it is not part of the DoubleLinkedList.h
void releaseDNode(DNode* node, void (*releaseData)(Object)){
	if(node){
		if(node->data){
			//ideally this should be a release function
			releaseData(node->data);
		}
		if(node->next){
			releaseDNode(node->next, releaseData);
		}
		free(node);
	}
}
示例#20
0
void Config::mapData( const eq::uint128_t& initDataID )
{
    if( !_initData.isAttached( ))
    {
        LBCHECK( mapObject( &_initData, initDataID ));
        releaseData(); // data was retrieved, unmap immediately
    }
    else  // appNode, _initData is registered already
    {
        LBASSERT( _initData.getID() == initDataID );
    }
}
示例#21
0
文件: Image.cpp 项目: rottaca/FreeCV
bool Image::init(int width, int height, PixelFormat f, unsigned char* data, bool copyData)
{
	bool recreateBuffer = m_width != width ||
			m_height != height ||
			m_format != f ||
			(data != NULL && copyData && !ownsMem());

	m_width = width;
	m_height = height;
	m_format = f;

	size_t buffSize = 0;
	switch (f) {
	case PF_GRAYSCALE_8:
		buffSize = width * height;
		m_bytesPerPixel = 1;
		break;
	case PF_RGB_888:
		buffSize = width * height * 3;
		m_bytesPerPixel = 3;
		break;
	case PF_FLOAT_32:
		buffSize = width * height * sizeof(float);
		m_bytesPerPixel = sizeof(float);
		break;
	case PF_YUYV:
		buffSize = width * height * 2;
		m_bytesPerPixel = 2;
		break;
	default:
		initEmpty();
		LOG_ERROR("Invalid Pixelformat speicifed!");
		return false;
	}

	if(recreateBuffer){
		releaseData();
		m_data = new unsigned char[buffSize];
		m_ownMem = true;
	}

	if (data != NULL) {
		m_ownMem = copyData || recreateBuffer;
		if (!copyData)
			m_data = data;
		else
			memcpy(m_data, data, buffSize);
	}
	return true;
}
示例#22
0
AlgorithmStatus Derivative::process() {
  AlgorithmStatus status = acquireData();

  if (status != OK) return status;

  const Real& input = _input.firstToken();
  Real& output = _output.firstToken();

  output = input - _oldValue;
  _oldValue = input;

  releaseData();

  return OK;
}
示例#23
0
AlgorithmStatus RingBufferOutput::process() {
  _impl->waitSpace();

  AlgorithmStatus status = acquireData();
  if (status != OK) return status;

  vector<AudioSample>& inputSignal = *((vector<AudioSample>*)input("signal").getTokens());
  AudioSample* inputData = &(inputSignal[0]);
  int inputSize = inputSignal.size();

  int size = _impl->add(inputData, inputSize);
  if (size != inputSize) throw EssentiaException("Not enough space in ringbuffer at output");
  releaseData();

  return OK;
}
示例#24
0
void PHNormalImage::loadToTexture(PHObject * sender, void * ud)
{	
    loadMutex->lock();
    if (loaded) {
        loadMutex->unlock();
        return;
    }
    
    tex = new PHGLTexture2D(gm);
    txc = tex->loadFromData(buffer, _width, _height, bw, bh, fmt, _antialiasing);
    _antialiasing = tex->minFilter() == PHGLTexture::linearMipmapNearest;
    releaseData();
    loaded = true;
    
    loadMutex->unlock();
}
示例#25
0
void StringData::assign(const char *data, int len, StringDataMode mode) {
  ASSERT(data);
  ASSERT(len >= 0);
  ASSERT(mode >= 0 && mode < StringDataModeCount);

  if (len < 0 || (len & IsMask)) {
    throw InvalidArgumentException("len: %d", len);
  }

  releaseData();
  m_hash = 0;
  m_len = len;
  if (m_len) {
    switch (mode) {
    case CopyString:
      {
        char *buf = (char*)malloc(len + 1);
        buf[len] = '\0';
        memcpy(buf, data, len);
        m_data = buf;
      }
      break;
    case AttachLiteral:
      m_len |= IsLiteral;
      m_data = data;
      ASSERT(m_data[len] == '\0');// all PHP strings need NULL termination
      break;
    case AttachString:
      m_data = data;
      ASSERT(m_data[len] == '\0');// all PHP strings need NULL termination
      break;
    default:
      ASSERT(false);
      break;
    }
  } else {
    if (mode == AttachString) {
      free((void*)data); // we don't really need a malloc-ed empty string
    }
    m_len |= IsLiteral;
    m_data = "";
  }
  ASSERT(m_data);
}
示例#26
0
void SensorDataReader::createFirstConnected()
{
	releaseData();

	std::string filename = GlobalAppState::get().s_binaryDumpSensorFile;

	std::cout << "Start loading binary dump... ";
	m_sensorData = new SensorData;
	m_sensorData->loadFromFile(filename);
	std::cout << "DONE!" << std::endl;
	std::cout << *m_sensorData << std::endl;

	//std::cout << "depth intrinsics:" << std::endl;
	//std::cout << m_sensorData->m_calibrationDepth.m_intrinsic << std::endl;
	//std::cout << "color intrinsics:" << std::endl;
	//std::cout << m_sensorData->m_calibrationColor.m_intrinsic << std::endl;

	RGBDSensor::init(m_sensorData->m_depthWidth, m_sensorData->m_depthHeight, std::max(m_sensorData->m_colorWidth, 1u), std::max(m_sensorData->m_colorHeight, 1u), 1);
	initializeDepthIntrinsics(m_sensorData->m_calibrationDepth.m_intrinsic(0, 0), m_sensorData->m_calibrationDepth.m_intrinsic(1, 1), m_sensorData->m_calibrationDepth.m_intrinsic(0, 2), m_sensorData->m_calibrationDepth.m_intrinsic(1, 2));
	initializeColorIntrinsics(m_sensorData->m_calibrationColor.m_intrinsic(0, 0), m_sensorData->m_calibrationColor.m_intrinsic(1, 1), m_sensorData->m_calibrationColor.m_intrinsic(0, 2), m_sensorData->m_calibrationColor.m_intrinsic(1, 2));

	initializeDepthExtrinsics(m_sensorData->m_calibrationDepth.m_extrinsic);
	initializeColorExtrinsics(m_sensorData->m_calibrationColor.m_extrinsic);


	m_numFrames = (unsigned int)m_sensorData->m_frames.size();
	if (m_numFrames > GlobalBundlingState::get().s_maxNumImages * GlobalBundlingState::get().s_submapSize) {
		throw MLIB_EXCEPTION("sens file #frames = " + std::to_string(m_numFrames) + ", please change param file to accommodate");
		//std::cout << "WARNING: sens file #frames = " << m_numFrames << ", please change param file to accommodate" << std::endl;
		//std::cout << "(press key to continue)" << std::endl;
		//getchar();
	}

	if (m_numFrames > 0 && m_sensorData->m_frames[0].getColorCompressed()) {
		m_bHasColorData = true;
	}
	else {
		m_bHasColorData = false;
	}

	const unsigned int cacheSize = 10;
	m_sensorDataCache = new ml::SensorData::RGBDFrameCacheRead(m_sensorData, cacheSize);
}
示例#27
0
void StringData::removeChar(int offset) {
  ASSERT(offset >= 0 && offset < size());
  int len = size();
  if (isImmutable()) {
    char *data = (char*)malloc(len);
    if (offset) {
      memcpy(data, this->data(), offset);
    }
    if (offset < len - 1) {
      memcpy(data + offset, this->data() + offset + 1, len - offset - 1);
    }
    data[len] = 0;
    m_len = len;
    releaseData();
    m_data = data;
  } else {
    m_len = ((m_len & IsMask) | (len - 1));
    memmove((void*)(m_data + offset), m_data + offset + 1, len - offset);
  }
}
示例#28
0
文件: Image.cpp 项目: rottaca/FreeCV
void Image::crop(Rectangle roi, Image* orgImg) {

	// Crop from own image
	if (orgImg == NULL && isValid()) {
		assert(roi.getTop() >= 0 && roi.getBottom() <= getHeight()
				&& roi.getLeft() >= 0 && roi.getRight() <= getWidth());
		// Temp buffer
		unsigned char* newBuff = new unsigned char[(int)(roi.getWidth()	* roi.getHeight() * getBytesPerPixel())];
		unsigned char* newBuffPtr = newBuff;

		LOG_DEBUG("Crop from own buffer");
		for (int h = roi.getTop(); h < roi.getBottom(); h++) {
			memcpy(newBuffPtr, getPtr<unsigned char>(h,roi.getLeft()),
					getBytesPerPixel() * roi.getWidth());

			newBuffPtr += (int)(getBytesPerPixel() * roi.getWidth());
		}
		if (m_ownMem)
			releaseData();

		m_data = newBuff;
		m_ownMem = true;
		m_width = roi.getWidth();
		m_height = roi.getHeight();

	}
	// Crop from other image
	else if(orgImg != NULL){
		assert(	roi.getTop() >= 0 && roi.getBottom() <= orgImg->getHeight()
				&& roi.getLeft() >= 0
				&& roi.getRight() <= orgImg->getWidth());

		init(roi.getWidth(), roi.getHeight(), orgImg->getFormat());
		for (int h = roi.getTop(); h < roi.getBottom(); h++) {
			memcpy(getPtr<unsigned char>(h), orgImg->getPtr<unsigned char>(h,roi.getLeft()),	orgImg->getBytesPerPixel() * roi.getWidth());
		}
	}else{
		LOG_ERROR("Can't crop from my own buffer. Not initialized!");
	}

}
示例#29
0
HRESULT BinaryDumpReader::createFirstConnected()
{
	releaseData();

	if (GlobalAppState::get().s_binaryDumpSensorFile.size() == 0) throw MLIB_EXCEPTION("need to specific s_binaryDumpSensorFile[0]");
	std::string filename = GlobalAppState::get().s_binaryDumpSensorFile[0];

	std::cout << "Start loading binary dump" << std::endl;
	//BinaryDataStreamZLibFile inputStream(filename, false);
	BinaryDataStreamFile inputStream(filename, false);
	inputStream >> m_data;
	std::cout << "Loading finished" << std::endl;
	std::cout << m_data << std::endl;

	std::cout << "intrinsics:" << std::endl;
	std::cout << m_data.m_CalibrationDepth.m_Intrinsic << std::endl;

	RGBDSensor::init(m_data.m_DepthImageWidth, m_data.m_DepthImageHeight, std::max(m_data.m_ColorImageWidth,1u), std::max(m_data.m_ColorImageHeight,1u), 1);
	initializeDepthIntrinsics(m_data.m_CalibrationDepth.m_Intrinsic(0,0), m_data.m_CalibrationDepth.m_Intrinsic(1,1), m_data.m_CalibrationDepth.m_Intrinsic(0,2), m_data.m_CalibrationDepth.m_Intrinsic(1,2));
	initializeColorIntrinsics(m_data.m_CalibrationColor.m_Intrinsic(0,0), m_data.m_CalibrationColor.m_Intrinsic(1,1), m_data.m_CalibrationColor.m_Intrinsic(0,2), m_data.m_CalibrationColor.m_Intrinsic(1,2));

	initializeDepthExtrinsics(m_data.m_CalibrationDepth.m_Extrinsic);
	initializeColorExtrinsics(m_data.m_CalibrationColor.m_Extrinsic);


	m_NumFrames = m_data.m_DepthNumFrames;
	assert(m_data.m_ColorNumFrames == m_data.m_DepthNumFrames || m_data.m_ColorNumFrames == 0);		
		
	if (m_data.m_ColorImages.size() > 0) {
		m_bHasColorData = true;
	} else {
		m_bHasColorData = false;
	}

	return S_OK;
}
示例#30
0
BinaryDumpReader::~BinaryDumpReader()
{
	releaseData();
}