예제 #1
0
파일: capxml.cpp 프로젝트: Skibol/MuseScore
Score::FileError importCapXml(Score* score, const QString& name)
      {
      qDebug("importCapXml(score %p, name %s)", score, qPrintable(name));
      QZipReader uz(name);
      if (!uz.exists()) {
            qDebug("importCapXml: <%s> not found", qPrintable(name));
            MScore::lastError = QT_TRANSLATE_NOOP("file", "file not found");
            return Score::FILE_NOT_FOUND;
            }

      QByteArray dbuf = uz.fileData("score.xml");
      XmlReader e(dbuf);
      e.setDocName(name);
      Capella cf;

      while (e.readNextStartElement()) {
            if (e.name() == "score") {
                  const QString& xmlns = e.attribute("xmlns", "<none>"); // doesn't work ???
                  qDebug("importCapXml: found score, namespace '%s'", qPrintable(xmlns));
                  cf.readCapx(e);
                  }
            else
                  e.unknown();
            }

      convertCapella(score, &cf, true);
      return Score::FILE_NO_ERROR;
      }
예제 #2
0
  void testQLDSolver()
  {
    BaseVariable xy("xy",2);
    BaseVariable z("z",1);
    CompositeVariable T("T", xy, z);

    MatrixXd A1(1,1); A1 << 1;
    VectorXd b1(1); b1 << -3;
    LinearFunction lf1(z, A1, b1);
    LinearConstraint c1(&lf1, true);

    MatrixXd A2(1,2); A2 << 3,1 ;
    VectorXd b2(1); b2 << 0;
    LinearFunction lf2(xy, A2, b2);
    LinearConstraint c2(&lf2, true);

    MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ;
    VectorXd b3(2); b3 << 0, 1;
    LinearFunction lf3(xy, A3, b3);
    LinearConstraint c3(&lf3, false);

    QuadraticFunction objFunc(T, Matrix3d::Identity(), Vector3d::Zero(), 0);
    QuadraticObjective obj(&objFunc);
    
    QLDSolver solver;
    solver.addConstraint(c1);
    solver.addConstraint(c2);
    solver.addConstraint(c3);
    solver.addObjective(obj);

    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);


    solver.removeConstraint(c1);
    IdentityFunction id(z);
    VectorXd lz(1); lz << 1;
    VectorXd uz(1); uz << 2;
    IdentityConstraint bnd1(&id, lz, uz);
    solver.addBounds(bnd1);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);

    BaseVariable t("t", 2);
    VectorXd ut(2); ut << -4,-1;
    BoundFunction bf(t, ut, BOUND_TYPE_SUPERIOR);
    BoundConstraint bnd2(&bf, false);
    solver.addBounds(bnd2);

    QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0);
    QuadraticObjective obj2(&objFunc2);
    solver.addObjective(obj2);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);

    Vector2d c3l(-1,-1);
    c3.setL(c3l);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);
  }
예제 #3
0
bool WBState::checkPose(Transformation3D &t)
{
		Vector3D wheels[4];

		double dw[4]={10000.0,10000.0,10000.0,10000.0};
		bool bw[4];
		//t.position.z+=robot->getWheelRadius();
		robot->setRelativeT3D(t);
		robot->getWheelsCenterPoints(wheels);
		robot->setIntersectable(false);
		Vector3D uz(0,0,-1);
		for(int j=0;j<4;j++)bw[j]=world->rayIntersection(wheels[j],uz,dw[j]);

		//si son menos de 3 lo considero como posicion invalida
		int nc=(bw[0]*1+bw[1]*1+bw[2]*1+bw[3]*1);
		if(nc<3)return false;

		//selecciono los dos menores: ordeno por indices
		int ord[4]={0,1,2,3};
		int i;
		for(i=1;i<4;i++)if(dw[ord[i]]<dw[ord[0]]){int c=ord[0];ord[0]=ord[i];ord[i]=c;}
		for(i=2;i<4;i++)if(dw[ord[i]]<dw[ord[1]]){int c=ord[1];ord[1]=ord[i];ord[i]=c;}
		if(dw[ord[3]]<dw[ord[2]]){int c=ord[2];ord[2]=ord[3];ord[3]=c;}
		//calculo los punto de contacto teóricos cayendo en z:
		Vector3D contact[4];
		for(i=0;i<4;i++)contact[i]=wheels[i]+uz*dw[i];
		//obtengo el vector del balancín con los dos más altos
		if(nc==4){
			Vector3D axis=(contact[ord[0]]-contact[ord[1]]).getUnitaryVector();
			Vector3D n=t.getVectorW();
			Vector3D nn=n-axis*(axis*n);
			//de los dos restantes proyecto sobre la nn y me quedo con el menor valor 
			double d2=nn*(contact[ord[0]]-contact[ord[2]]);
			double d3=nn*(contact[ord[0]]-contact[ord[3]]);
			if(d3<d2)ord[2]=ord[3];
		}
		//ahora los tres puntos estan obtenidos: lo transformamos en un sdr coherente con la plataforma
		bool flag[4]={false,false,false,false};
		for(i=0;i<3;i++)flag[ord[i]]=true;
		Vector3D vu,vv,vw,npos;
		//nueva posición:
		if(flag[0]&&flag[3])npos=(contact[0]+contact[3])*0.5;
		if(flag[1]&&flag[2])npos=(contact[1]+contact[2])*0.5;
		//nueva orientación:
		if(flag[0]&&flag[2])vu=(contact[0]-contact[2]).getUnitaryVector();
		if(flag[1]&&flag[3])vu=(contact[1]-contact[3]).getUnitaryVector();
		if(flag[0]&&flag[1])vv=(contact[0]-contact[1]).getUnitaryVector();
		if(flag[2]&&flag[3])vv=(contact[2]-contact[3]).getUnitaryVector();

		Transformation3D drop;
		drop.position=npos;
		drop.orientation=OrientationMatrix(vu,vv);

		if(Vector3D(0,0,1)*drop.getVectorW()<0.7)return false; //maximum admisible inclination (45º)
		t=drop;
		robot->setRelativeT3D(t);
		return true;
}
예제 #4
0
Score::FileError MasterScore::loadCompressedMsc(QIODevice* io, bool ignoreVersionError)
      {
      MQZipReader uz(io);

      QList<QString> sl;
      QString rootfile = readRootFile(&uz, sl);
      if (rootfile.isEmpty())
            return FileError::FILE_NO_ROOTFILE;

      //
      // load images
      //
      if (!MScore::noImages) {
            foreach(const QString& s, sl) {
                  QByteArray dbuf = uz.fileData(s);
                  imageStore.add(s, dbuf);
                  }
예제 #5
0
bool ZInstrument::loadFromFile(const QString& path)
      {
      if (path.endsWith(".sfz"))
            return loadSfz(path);
      if (!path.endsWith(".msoz")) {
            printf("<%s> not a orchestra file\n", qPrintable(path));
            return false;
            }
      MQZipReader uz(path);
      if (!uz.exists()) {
            printf("Instrument::load: %s not found\n", qPrintable(path));
            return false;
            }
      QByteArray buf = uz.fileData("orchestra.xml");
      if (buf.isEmpty()) {
            printf("Instrument::loadFromFile: orchestra.xml not found\n");
            return false;
            }
      return read(buf, &uz, QString());
      }
예제 #6
0
bool Score::saveCompressedFile(QIODevice* f, QFileInfo& info, bool onlySelection, bool doCreateThumbnail)
      {
      MQZipWriter uz(f);

      QString fn = info.completeBaseName() + ".mscx";
      QBuffer cbuf;
      cbuf.open(QIODevice::ReadWrite);
      XmlWriter xml(this, &cbuf);
      xml << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
      xml.stag("container");
      xml.stag("rootfiles");
      xml.stag(QString("rootfile full-path=\"%1\"").arg(XmlWriter::xmlString(fn)));
      xml.etag();
      for (ImageStoreItem* ip : imageStore) {
            if (!ip->isUsed(this))
                  continue;
            QString path = QString("Pictures/") + ip->hashName();
            xml.tag("file", path);
            }

      xml.etag();
      xml.etag();
      cbuf.seek(0);
      //uz.addDirectory("META-INF");
      uz.addFile("META-INF/container.xml", cbuf.data());

      // save images
      //uz.addDirectory("Pictures");
      foreach (ImageStoreItem* ip, imageStore) {
            if (!ip->isUsed(this))
                  continue;
            QString path = QString("Pictures/") + ip->hashName();
            uz.addFile(path, ip->buffer());
            }

      // create thumbnail
      if (doCreateThumbnail && !pages().isEmpty()) {
            QImage pm = createThumbnail();

            QByteArray ba;
            QBuffer b(&ba);
            if (!b.open(QIODevice::WriteOnly))
                  qDebug("open buffer failed");
            if (!pm.save(&b, "PNG"))
                  qDebug("save failed");
            uz.addFile("Thumbnails/thumbnail.png", ba);
            }

#ifdef OMR
      //
      // save OMR page images
      //
      if (masterScore()->omr()) {
            int n = masterScore()->omr()->numPages();
            for (int i = 0; i < n; ++i) {
                  QString path = QString("OmrPages/page%1.png").arg(i+1);
                  QBuffer cbuf1;
                  OmrPage* page = masterScore()->omr()->page(i);
                  const QImage& image = page->image();
                  if (!image.save(&cbuf1, "PNG")) {
                        MScore::lastError = tr("save file: cannot save image (%1x%2)").arg(image.width(), image.height());
                        return false;
                        }
                  uz.addFile(path, cbuf1.data());
                  cbuf1.close();
                  }
            }
#endif
      //
      // save audio
      //
      if (_audio)
            uz.addFile("audio.ogg", _audio->data());

      QBuffer dbuf;
      dbuf.open(QIODevice::ReadWrite);
      saveFile(&dbuf, true, onlySelection);
      dbuf.seek(0);
      uz.addFile(fn, dbuf.data());
      uz.close();
      return true;
      }
예제 #7
0
	/// Get forward unit vector (negative of Z)
	Vec3d uf() const { return -uz(); }
예제 #8
0
bool PaletteLoader_Swatchbook::importFile(const QString& fileName, bool /*merge*/)
{
	ScColor lf;
	int oldCount = m_colors->count();
	
	QScopedPointer<ScZipHandler> uz(new ScZipHandler());
	if (!uz->open(fileName))
		return false;
	if (!uz->contains("swatchbook.xml"))
		return false;
	
	QByteArray docBytes;
	if (!uz->read("swatchbook.xml", docBytes))
		return false;

	QString docText = QString::fromUtf8(docBytes);
	QDomDocument docu("scridoc");
	if (!docu.setContent(docText))
		return false;
	
	QDomElement docElem = docu.documentElement();
	for (QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
	{
		if (drawPag.tagName() == "materials")
		{
			for (QDomElement spf = drawPag.firstChildElement(); !spf.isNull(); spf = spf.nextSiblingElement() )
			{
				if (spf.tagName() == "color")
				{
					bool isSpot = spf.attribute("usage") == "spot";
					QString colorName = "";
					ScColor tmp;
					tmp.setRegistrationColor(false);
					for (QDomElement spp = spf.firstChildElement(); !spp.isNull(); spp = spp.nextSiblingElement() )
					{
						if (spp.tagName() == "metadata")
						{
							for (QDomElement spm = spp.firstChildElement(); !spm.isNull(); spm = spm.nextSiblingElement() )
							{
								if (spm.tagName() == "dc:identifier")
									colorName = spm.text();
							}
						}
						else if (spp.tagName() == "values")
						{
							QString colorVals = spp.text();
							ScTextStream CoE(&colorVals, QIODevice::ReadOnly);
							if (spp.attribute("model") == "Lab")
							{
								double inC[3];
								CoE >> inC[0];
								CoE >> inC[1];
								CoE >> inC[2];
								tmp.setLabColor(inC[0], inC[1], inC[2]);
								tmp.setSpotColor(isSpot);
							}
							else if (spp.attribute("model") == "CMYK")
							{
								double c, m, y, k;
								CoE >> c >> m >> y >> k;
								tmp.setColorF(c, m, y, k);
								tmp.setSpotColor(isSpot);
							}
							else if (spp.attribute("model") == "RGB")
							{
								double r, g, b;
								CoE >> r >> g >> b;
								tmp.setRgbColorF(r, g, b);
								tmp.setSpotColor(false);
							}
예제 #9
0
파일: main.cpp 프로젝트: ashkan2200/FDM
void MMS(vector<myData> & F_out, vector<myData> & Ftt_out, FDM::baseSolver& sol, const vector<myData>& u,int step,double t, void * args){
    double x = 0;
    double y = 0;
    double z = 0;
    
    int LN_X = sol.X_LayerNumber();
    int LN_Y = sol.Y_LayerNumber();
    int LN_Z = sol.Z_LayerNumber();
    
    int Nx,Ny,Nz;
    int index = 0;
    for (int lz = 0; lz < LN_Z; lz++) {
        for (int ly = 0; ly < LN_Y; ly++) {
            for (int lx = 0; lx < LN_X; lx++) {
                
                index = idx(lx, ly, lz);
                Nx = u[index].Nx();
                Ny = u[index].Ny();
                Nz = u[index].Nz();
                
                myData ux(Nx,Ny,Nz);
                myData uy(Nx,Ny,Nz);
                myData uz(Nx,Ny,Nz);
                
                myData Bux(Nx,Ny,Nz);
                myData Buy(Nx,Ny,Nz);
                myData Buz(Nx,Ny,Nz);
                
                for (int k = 0; k < Nz; k++) {
                    z = sol.Z(k,lz);
                    for (int j = 0; j < Ny; j++) {
                        y = sol.Y(j,ly);
                        for (int i = 0; i < Nx; i++) {
                            x = sol.X(i,lx);
                            
                            
                            F_out[index](i,j,k)     =  8*M_PI*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z);
                            Ftt_out[index](i,j,k)   = -4*M_PI*M_PI*F_out[index](i,j,k);
                            
                            ux(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*sin(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z);//ux boundary
                            uy(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*sin(2*M_PI*y)*cos(2*M_PI*z);//uy
                            uz(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*cos(2*M_PI*y)*sin(2*M_PI*z);//uz
                        }
                    }
                }
                
                //Bux setup
                if (lx == 0) {
                    for (int k = 0; k < Nz; k++) {
                        for (int j = 0; j < Ny; j++) {
                            Bux(0,j,k) = -1;
                        }
                    }
                }
                
                if (lx == LN_X - 1) {
                    for (int k = 0; k < Nz; k++) {
                        for (int j = 0; j < Ny; j++) {
                            Bux(Nx - 1,j,k) = 1;
                        }
                    }
                }
                //
                
                ///Buy setup
                if (ly == 0) {
                    for (int k = 0; k < Nz; k++) {
                        for (int i = 0; i < Nx; i++) {
                            Buy(i,0,k) = -1;
                        }
                    }
                }
                
                if (ly == LN_Y - 1) {
                    for (int k = 0; k < Nz; k++) {
                        for (int i = 0; i < Nx; i++) {
                            Buy(i,Ny - 1,k) = 1;
                        }
                    }
                }
                //
                
                //Buz setup
                if (lz == 0) {
                    for (int j = 0; j < Ny; j++) {
                        for (int i = 0; i < Nx; i++) {
                            Buz(i,j,0) = -1;
                        }
                    }
                }
                
                if (lz == LN_Z - 1) {
                    for (int j = 0; j < Ny; j++) {
                        for (int i = 0; i < Nx; i++) {
                            Buz(i,j,Nz - 1) = 1;
                        }
                    }
                }
                //
                
                F_out[index] += sol.H_INV()*(Bux*ux + Buy*uy + Buz*uz);
            }
        }
    }
}