void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRect& srcRect, const FloatRect& dstRect,
    ExceptionCode& ec)
{
    ASSERT(image);

    ec = 0;

    FloatRect imageRect = FloatRect(FloatPoint(), size(image));
    if (!(imageRect.contains(srcRect) && srcRect.width() >= 0 && srcRect.height() >= 0 
            && dstRect.width() >= 0 && dstRect.height() >= 0)) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (srcRect.isEmpty() || dstRect.isEmpty())
        return;

    GraphicsContext* c = drawingContext();
    if (!c)
        return;

    CachedImage* cachedImage = image->cachedImage();
    if (!cachedImage)
        return;

    if (m_canvas->originClean())
        checkOrigin(KURL(cachedImage->url()));

    FloatRect sourceRect = c->roundToDevicePixels(srcRect);
    FloatRect destRect = c->roundToDevicePixels(dstRect);
    willDraw(destRect);
    c->drawImage(cachedImage->image(), destRect, sourceRect, state().m_globalComposite);
}
// FIXME: Why isn't this just another overload of drawImage? Why have a different name?
void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
    float sx, float sy, float sw, float sh,
    float dx, float dy, float dw, float dh,
    const String& compositeOperation)
{
    if (!image)
        return;

    CachedImage* cachedImage = image->cachedImage();
    if (!cachedImage)
        return;

    if (m_canvas->originClean())
        checkOrigin(KURL(cachedImage->url()));

    GraphicsContext* c = drawingContext();
    if (!c)
        return;

    CompositeOperator op;
    if (!parseCompositeOperator(compositeOperation, op))
        op = CompositeSourceOver;

    FloatRect destRect = FloatRect(dx, dy, dw, dh);
    willDraw(destRect);
    c->drawImage(cachedImage->image(), destRect, FloatRect(sx, sy, sw, sh), op);
}
void CanvasRenderingContext::checkOrigin(const HTMLVideoElement* video)
{
#if ENABLE(VIDEO)
    checkOrigin(KURL(KURL(), video->currentSrc()));
    if (canvas()->originClean() && video && !video->hasSingleSecurityOrigin())
        canvas()->setOriginTainted();
#endif
}
void CanvasRenderingContext::checkOrigin(const HTMLImageElement* image)
{
    if (!image || !canvas()->originClean())
        return;

    CachedImage* cachedImage = image->cachedImage();
    checkOrigin(cachedImage->response().url());

    if (canvas()->originClean() && !cachedImage->image()->hasSingleSecurityOrigin())
        canvas()->setOriginTainted();
}
bool SteerLib::GJK_EPA::gjk(const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB, std::vector<Util::Vector>& simplex) {
	Util::Vector dir(1,0,0);

	simplex.push_back((getFarPoint(_shapeA, dir) - getFarPoint(_shapeB, -dir)));
	dir = -dir;
	
	while(true){
		float dotProduct = 0;
		simplex.push_back((getFarPoint(_shapeA, dir) - getFarPoint(_shapeB, -dir)));

		if(dotProd(simplex.back(), dir) <= 0) 
			return false;
		else if (checkOrigin(simplex, dir)){
			simplex.push_back((getFarPoint(_shapeA, dir) - getFarPoint(_shapeB, -dir)));
			return true;
		}
	}
}
Exemple #6
0
void
EigenGraspInterface::setOrigin(const double *dof)
{
	mOrigin->setEigenGrasp(dof);
	checkOrigin();
}
Exemple #7
0
/*! Reads the entire interface from a file, looking for keywords 
	inside the file. Loads the size of the dof space, all eg's
	(which define the size of the eg space), any normalization
	factors (optional) and the origin of the eg space (optional).

	The size of the dof space must be loaded before any eg's, 
	origin, etc can be loaded; is must also match the number of
	dof's in this robot.
*/
int
EigenGraspInterface::readFromFile(QString filename)
{
	QFile file(filename);
	if (!file.open(QIODevice::ReadOnly)) {
		DBGA("Failed to open EG file: " << filename.latin1());
		return 0;
	}
	QTextStream stream( &file );

	clear();
	int numDims = 0;
	QString line,id;
	bool error = false;
	while (!error && !stream.atEnd() ) {
		line = stream.readLine();
		line.stripWhiteSpace();
		id = line.section(' ',0,0);
		if (id == "DIMENSIONS") {
			numDims = line.section(' ',1,1).toInt();
			if (numDims != mRobot->getNumDOF()) {
				DBGA("ERROR reading eigengrasp: appears to be constructed for another robot.");
			}
		} else if ( id == "EG" ) {
			if (!numDims) {DBGA("Number of dimensions not specified!"); error = true; continue;}
			EigenGrasp *newGrasp = new EigenGrasp(numDims);
			if (!newGrasp->readFromStream(&stream)) {error = true; continue;}
			newGrasp->normalize();
			mGrasps.push_back(newGrasp);
		} else if ( id == "ORIGIN" ) {
			if (!numDims) {DBGA("Number of dimensions not specified!"); error = true; continue;}
			mOrigin = new EigenGrasp(numDims);
			if (!mOrigin->readFromStream(&stream)){error = true; continue;}
			checkOrigin();
		} else if ( id == "NORM" ) {
			if (!numDims) {DBGA("Number of dimensions not specified!"); error = true; continue;}
			mNorm = new EigenGrasp(numDims);
			if (!mNorm->readFromStream(&stream)){error = true; continue;}
			DBGA("EG Normalization data loaded from file");
		}
	}
	if (error) {
		DBGA("Error reading EG file");
		return 0;
	}

	eSize = mGrasps.size();
	DBGA("Read " << eSize << " eigengrasps from EG file");
	if (!mNorm) {
		DBGA("No normalization data found; using factors of 1.0");
		mNorm = new EigenGrasp(dSize);
		mNorm->setOnes();
	}
	if (!mOrigin) {
		DBGA("No EG origin found; using automatic origin");
		mOrigin = new EigenGrasp(dSize);
		setSimpleOrigin();
	}
	computeProjectionMatrices();
	setMinMax();
	return 1;
}
Exemple #8
0
/*! Reads the entire interface from a file, looking for keywords 
	inside the file. Loads the size of the dof space, all eg's
	(which define the size of the eg space), any normalization
	factors (optional) and the origin of the eg space (optional).

	The size of the dof space must be loaded before any eg's, 
	origin, etc can be loaded; is must also match the number of
	dof's in this robot.
*/
int
EigenGraspInterface::readFromFile(QString filename)
{
    //open xml file at "filename"
    	bool ok;
    	QString fileType = filename.section('.',-1,-1);
	QString xmlFilename;
	if (fileType == "xml"){
		//the file itself is XML
		xmlFilename = filename;
	} else {
	    	QTWARNING("Could not open " + xmlFilename);
		DBGA("Old non-xml file format is no longer supported");
		return 0;
	}

    	//load the graspit specific information in XML format or fail
	TiXmlDocument doc(xmlFilename);
	if(doc.LoadFile()==false){
		DBGA("Failed to open EG file: " << filename.latin1());
		QTWARNING("Could not open " + xmlFilename);
		return 0;
	}
    //get the dimensions
	int numDims = 0;
	QString valueStr;
	clear();
	TiXmlElement* root = doc.RootElement();
    	if(root == NULL){
		DBGA("The "<<filename.toStdString()<<" file must contain a root tag named EigenGrasps.");
		return 0;
	} else{
		valueStr = root->Attribute("dimensions");
		numDims = valueStr.toDouble(&ok); if (!ok) {DBGA("ERROR: Dimension should contain a number.");return 0;}
		if (numDims <= 0) {
		    	DBGA("invalid number of dimensions in EigenGrasps tag in file: "<<filename.toStdString());
			return 0;
		}
	}

    //get the list of EG's 
	std::list<const TiXmlElement*> elementList = findAllXmlElements(root, "EG");
	int numEG = countXmlElements(root, "EG");
	if (numEG < 1) {
		DBGA("Number of Eigengrasps specified: " << numEG);
		return 0;
	}
	std::list<const TiXmlElement*>::iterator p = elementList.begin();
	while(p!=elementList.end()){
		EigenGrasp *newGrasp = new EigenGrasp(numDims);
	    	if (!newGrasp->readFromXml(*p++)) return 0;
		newGrasp->normalize();
		mGrasps.push_back(newGrasp);
	}


    //get the orgin and process (if none setsimpleorgin)
	elementList = findAllXmlElements(root, "ORIGIN");
	int numORG = countXmlElements(root, "ORIGIN");
	if (!numORG) {
	    	DBGA("No EG origin found; using automatic origin");
		mOrigin = new EigenGrasp(numDims);
		setSimpleOrigin();
	}
	else if(numORG==1)
	{
		mOrigin = new EigenGrasp(numDims);
		if (!mOrigin->readFromXml(*(elementList.begin()))){ return 0;}
		checkOrigin();
	}
	else
	{
	    	DBGA("Multiple Origins specified in Eigen Grasp file.");
		return 0;
	}

    //get the norm and process (if none set to all 1's)
	elementList = findAllXmlElements(root, "NORM");
	int numNORM = countXmlElements(root, "NORM");
	if (!numNORM) {
		DBGA("No normalization data found; using factors of 1.0");
		mNorm = new EigenGrasp(numDims);
		mNorm->setOnes();
	}
	else if(numNORM==1)
	{
		mNorm = new EigenGrasp(numDims);
		if (!mNorm->readFromXml(*(elementList.begin()))){ return 0;}
		DBGA("EG Normalization data loaded from file");
	}
	else
	{
	    	DBGA("Multiple Normals specified in Eigen Grasp file.");
	    	return 0;
	}

	eSize = mGrasps.size();
	DBGA("Read " << eSize << " eigengrasps from EG file");

	computeProjectionMatrices();
	setMinMax();
	return 1;
}