Example #1
0
//
//	Drag and drop mode decorations
//		Before click: standard vertex selection pointer (yellow)
//		After select: draw each new edge with yellow lines
//
void edit_topo::editDecoDragAndDropVertex(MeshModel &m)
{
	if(drag_click)
	{
		Point3f pmouse;
		if(Pick(mousePos.x(), mouseRealY, pmouse))
		{			
			for(int i=0; i<drag_stack.count(); i++)
			{
				Fce fc = drag_stack.at(i);

				QList<Vtx> allv;
				for(int e=0; e<3; e++)
					for(int v=0; v<2; v++)
						if(!allv.contains(fc.e[e].v[v]))
							allv.push_back(fc.e[e].v[v]);

				QVector<Vtx> v = allv.toVector();
				
				for(int i=0; i<3; i++)
					if(v[i] == drag_vtx)
						v[i].V = pmouse;

				drawLine(Color4b::Yellow, Color4b::Yellow, v[0].V, v[1].V);
				drawLine(Color4b::Yellow, Color4b::Yellow, v[1].V, v[2].V);
				drawLine(Color4b::Yellow, Color4b::Yellow, v[2].V, v[0].V);
			}
		}
	}
	else
	{
		Vtx vtx;
		if(getVisibleVertexNearestToMouse(stack, vtx))
			drawPoint(m, 4.0f, Color4b::Yellow, vtx.V);

	}
}
static QList<double> _calcJenksBreaks( QList<double> values, int classes,
                                       double minimum, double maximum,
                                       int maximumSize = 1000 )
{
  // Jenks Optimal (Natural Breaks) algorithm
  // Based on the Jenks algorithm from the 'classInt' package available for
  // the R statistical prgramming language, and from Python code from here:
  // http://danieljlewis.org/2010/06/07/jenks-natural-breaks-algorithm-in-python/
  // and is based on a JAVA and Fortran code available here:
  // https://stat.ethz.ch/pipermail/r-sig-geo/2006-March/000811.html

  // Returns class breaks such that classes are internally homogeneous while
  // assuring heterogeneity among classes.

  if ( !values.count() )
    return QList<double>();

  if ( classes <= 1 )
  {
    return QList<double>() << maximum;
  }

  if ( classes >= values.size() )
  {
    return values;
  }

  QVector<double> sample;

  // if we have lots of values, we need to take a random sample
  if ( values.size() > maximumSize )
  {
    // for now, sample at least maximumSize values or a 10% sample, whichever
    // is larger. This will produce a more representative sample for very large
    // layers, but could end up being computationally intensive...

    qsrand( time( 0 ) );

    sample.resize( qMax( maximumSize, values.size() / 10 ) );

    QgsDebugMsg( QString( "natural breaks (jenks) sample size: %1" ).arg( sample.size() ) );
    QgsDebugMsg( QString( "values:%1" ).arg( values.size() ) );

    sample[ 0 ] = minimum;
    sample[ 1 ] = maximum;;
    for ( int i = 2; i < sample.size(); i++ )
    {
      // pick a random integer from 0 to n
      double r = qrand();
      int j = floor( r / RAND_MAX * ( values.size() - 1 ) );
      sample[ i ] = values[ j ];
    }
  }
  else
  {
    sample = values.toVector();
  }

  int n = sample.size();

  // sort the sample values
  qSort( sample );

  QVector< QVector<int> > matrixOne( n + 1 );
  QVector< QVector<double> > matrixTwo( n + 1 );

  for ( int i = 0; i <= n; i++ )
  {
    matrixOne[i].resize( classes + 1 );
    matrixTwo[i].resize( classes + 1 );
  }

  for ( int i = 1; i <= classes; i++ )
  {
    matrixOne[0][i] = 1;
    matrixOne[1][i] = 1;
    matrixTwo[0][i] = 0.0;
    for ( int j = 2; j <= n; j++ )
    {
      matrixTwo[j][i] = std::numeric_limits<double>::max();
    }
  }

  for ( int l = 2; l <= n; l++ )
  {
    double s1 = 0.0;
    double s2 = 0.0;
    int w = 0;

    double v = 0.0;

    for ( int m = 1; m <= l; m++ )
    {
      int i3 = l - m + 1;

      double val = sample[ i3 - 1 ];

      s2 += val * val;
      s1 += val;
      w++;

      v = s2 - ( s1 * s1 ) / ( double ) w;
      int i4 = i3 - 1;
      if ( i4 != 0 )
      {
        for ( int j = 2; j <= classes; j++ )
        {
          if ( matrixTwo[l][j] >= v + matrixTwo[i4][j - 1] )
          {
            matrixOne[l][j] = i4;
            matrixTwo[l][j] = v + matrixTwo[i4][j - 1];
          }
        }
      }
    }
    matrixOne[l][1] = 1;
    matrixTwo[l][1] = v;
  }

  QVector<double> breaks( classes );
  breaks[classes-1] = sample[n-1];

  for ( int j = classes, k = n; j >= 2; j-- )
  {
    int id = matrixOne[k][j] - 1;
    breaks[j - 2] = sample[id];
    k = matrixOne[k][j] - 1;
  }

  return breaks.toList();
} //_calcJenksBreaks
Example #3
0
void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
{
  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );

  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  //add point to list and to rubber band
  if ( e->button() == Qt::LeftButton )
  {
    int error = addVertex( e->mapPoint() );
    if ( error == 1 )
    {
      //current layer is not a vector layer
      return;
    }
    else if ( error == 2 )
    {
      //problem with coordinate transformation
      emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
      return;
    }

    startCapturing();
  }
  else if ( e->button() == Qt::RightButton )
  {
    if ( !isCapturing() )
      return;

    deleteTempRubberBand();

    closePolygon();

    vlayer->beginEditCommand( tr( "Ring added and filled" ) );
    QList< QgsPoint > pointList = points();

    QgsFeatureId modifiedFid;
    int addRingReturnCode = vlayer->addRing( pointList, &modifiedFid );
    if ( addRingReturnCode != 0 )
    {
      QString errorMessage;
      //todo: open message box to communicate errors
      if ( addRingReturnCode == 1 )
      {
        errorMessage = tr( "a problem with geometry type occured" );
      }
      else if ( addRingReturnCode == 2 )
      {
        errorMessage = tr( "the inserted Ring is not closed" );
      }
      else if ( addRingReturnCode == 3 )
      {
        errorMessage = tr( "the inserted Ring is not a valid geometry" );
      }
      else if ( addRingReturnCode == 4 )
      {
        errorMessage = tr( "the inserted Ring crosses existing rings" );
      }
      else if ( addRingReturnCode == 5 )
      {
        errorMessage = tr( "the inserted Ring is not contained in a feature" );
      }
      else
      {
        errorMessage = tr( "an unknown error occured" );
      }
      emit messageEmitted( tr( "could not add ring since %1." ).arg( errorMessage ), QgsMessageBar::CRITICAL );
      vlayer->destroyEditCommand();
    }
    else
    {
      // find parent feature and get it attributes
      double xMin, xMax, yMin, yMax;
      QgsRectangle bBox;

      xMin = std::numeric_limits<double>::max();
      xMax = -std::numeric_limits<double>::max();
      yMin = std::numeric_limits<double>::max();
      yMax = -std::numeric_limits<double>::max();

      Q_FOREACH ( const QgsPoint& point, pointList )
      {
        xMin = qMin( xMin, point.x() );
        xMax = qMax( xMax, point.x() );
        yMin = qMin( yMin, point.y() );
        yMax = qMax( yMax, point.y() );
      }

      bBox.setXMinimum( xMin );
      bBox.setYMinimum( yMin );
      bBox.setXMaximum( xMax );
      bBox.setYMaximum( yMax );

      QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterFid( modifiedFid ) );

      QgsFeature f;
      bool res = false;
      if ( fit.nextFeature( f ) )
      {
        //create QgsFeature with wkb representation
        QgsFeature* ft = new QgsFeature( vlayer->fields(), 0 );

        ft->setGeometry( QgsGeometry::fromPolygon( QgsPolygon() << pointList.toVector() ) );
        ft->setAttributes( f.attributes() );

        if ( QApplication::keyboardModifiers() == Qt::ControlModifier )
        {
          res = vlayer->addFeature( *ft );
        }
        else
        {
          QgsAttributeDialog *dialog = new QgsAttributeDialog( vlayer, ft, false, NULL, true );
          dialog->setIsAddDialog( true );
          res = dialog->exec(); // will also add the feature
        }

        if ( res )
        {
          vlayer->endEditCommand();
        }
        else
        {
          delete ft;
          vlayer->destroyEditCommand();
        }
        res = false;
      }
    }
    stopCapturing();
  }
  bool QTAIMWavefunction::initializeWithMoleculeProperties( Molecule*& mol )
  {

    if( mol->property( "QTAIMNumberOfMolecularOrbitals" ).isValid() )
    {

      QVariant numberOfMolecularOrbitalsVariant = mol->property( "QTAIMNumberOfMolecularOrbitals" );
      m_numberOfMolecularOrbitals=numberOfMolecularOrbitalsVariant.toLongLong();

      QVariant numberOfGaussianPrimitivesVariant = mol->property( "QTAIMNumberOfGaussianPrimitives" );
      m_numberOfGaussianPrimitives=numberOfGaussianPrimitivesVariant.toLongLong();

      QVariant numberOfNucleiVariant = mol->property( "QTAIMNumberOfNuclei" );
      m_numberOfNuclei=numberOfNucleiVariant.toLongLong();

      QVariant xNuclearCoordinatesVariant = mol->property( "QTAIMXNuclearCoordinates");
      QVariant yNuclearCoordinatesVariant = mol->property( "QTAIMYNuclearCoordinates");
      QVariant zNuclearCoordinatesVariant = mol->property( "QTAIMZNuclearCoordinates");
      QVariant nuclearChargesVariant = mol->property( "QTAIMNuclearCharges" );
      QVariantList xNuclearCoordinatesVariantList = xNuclearCoordinatesVariant.toList();
      QVariantList yNuclearCoordinatesVariantList = yNuclearCoordinatesVariant.toList();
      QVariantList zNuclearCoordinatesVariantList = zNuclearCoordinatesVariant.toList();
      QVariantList nuclearChargesVariantList = nuclearChargesVariant.toList();
      QList<qreal> xNuclearCoordinatesList;
      QList<qreal> yNuclearCoordinatesList;
      QList<qreal> zNuclearCoordinatesList;
      QList<qint64> nuclearChargesList;
      for( qint64 i=0 ; i < m_numberOfNuclei ; ++i )
      {
        xNuclearCoordinatesList.append( xNuclearCoordinatesVariantList.at(i).toReal() );
        yNuclearCoordinatesList.append( yNuclearCoordinatesVariantList.at(i).toReal() );
        zNuclearCoordinatesList.append( zNuclearCoordinatesVariantList.at(i).toReal() );
        nuclearChargesList.append( nuclearChargesVariantList.at(i).toLongLong() );
      }
      m_xNuclearCoordinates=xNuclearCoordinatesList.toVector();
      m_yNuclearCoordinates=yNuclearCoordinatesList.toVector();
      m_zNuclearCoordinates=zNuclearCoordinatesList.toVector();
      m_nuclearCharges=nuclearChargesList.toVector();

      QVariant xGaussianPrimitiveCenterCoordinatesVariant = mol->property( "QTAIMXGaussianPrimitiveCenterCoordinates" );
      QVariant yGaussianPrimitiveCenterCoordinatesVariant = mol->property( "QTAIMYGaussianPrimitiveCenterCoordinates" );
      QVariant zGaussianPrimitiveCenterCoordinatesVariant = mol->property( "QTAIMZGaussianPrimitiveCenterCoordinates" );
      QVariant xGaussianPrimitiveAngularMomentaVariant = mol->property( "QTAIMXGaussianPrimitiveAngularMomenta" );
      QVariant yGaussianPrimitiveAngularMomentaVariant = mol->property( "QTAIMYGaussianPrimitiveAngularMomenta" );
      QVariant zGaussianPrimitiveAngularMomentaVariant = mol->property( "QTAIMZGaussianPrimitiveAngularMomenta" );
      QVariant gaussianPrimitiveExponentCoefficientsVariant = mol->property( "QTAIMGaussianPrimitiveExponentCoefficients" );
      QVariantList xGaussianPrimitiveCenterCoordinatesVariantList = xGaussianPrimitiveCenterCoordinatesVariant.toList();
      QVariantList yGaussianPrimitiveCenterCoordinatesVariantList = yGaussianPrimitiveCenterCoordinatesVariant.toList();
      QVariantList zGaussianPrimitiveCenterCoordinatesVariantList = zGaussianPrimitiveCenterCoordinatesVariant.toList();
      QVariantList xGaussianPrimitiveAngularMomentaVariantList = xGaussianPrimitiveAngularMomentaVariant.toList();
      QVariantList yGaussianPrimitiveAngularMomentaVariantList = yGaussianPrimitiveAngularMomentaVariant.toList();
      QVariantList zGaussianPrimitiveAngularMomentaVariantList = zGaussianPrimitiveAngularMomentaVariant.toList();
      QVariantList gaussianPrimitiveExponentCoefficientsVariantList = gaussianPrimitiveExponentCoefficientsVariant.toList();
      QList<qreal> xGaussianPrimitiveCenterCoordinatesList;
      QList<qreal> yGaussianPrimitiveCenterCoordinatesList;
      QList<qreal> zGaussianPrimitiveCenterCoordinatesList;
      QList<qint64> xGaussianPrimitiveAngularMomentaList;
      QList<qint64> yGaussianPrimitiveAngularMomentaList;
      QList<qint64> zGaussianPrimitiveAngularMomentaList;
      QList<qreal> gaussianPrimitiveExponentCoefficientsList;

      for( qint64 p=0 ; p < m_numberOfGaussianPrimitives ; ++p )
      {
        xGaussianPrimitiveCenterCoordinatesList.append(xGaussianPrimitiveCenterCoordinatesVariantList.at(p).toReal());
        yGaussianPrimitiveCenterCoordinatesList.append(yGaussianPrimitiveCenterCoordinatesVariantList.at(p).toReal());
        zGaussianPrimitiveCenterCoordinatesList.append(zGaussianPrimitiveCenterCoordinatesVariantList.at(p).toReal());
        xGaussianPrimitiveAngularMomentaList.append(xGaussianPrimitiveAngularMomentaVariantList.at(p).toLongLong());
        yGaussianPrimitiveAngularMomentaList.append(yGaussianPrimitiveAngularMomentaVariantList.at(p).toLongLong());
        zGaussianPrimitiveAngularMomentaList.append(zGaussianPrimitiveAngularMomentaVariantList.at(p).toLongLong());
        gaussianPrimitiveExponentCoefficientsList.append(gaussianPrimitiveExponentCoefficientsVariantList.at(p).toReal());
      }

      m_xGaussianPrimitiveCenterCoordinates=xGaussianPrimitiveCenterCoordinatesList.toVector();
      m_yGaussianPrimitiveCenterCoordinates=yGaussianPrimitiveCenterCoordinatesList.toVector();
      m_zGaussianPrimitiveCenterCoordinates=zGaussianPrimitiveCenterCoordinatesList.toVector();
      m_xGaussianPrimitiveAngularMomenta=xGaussianPrimitiveAngularMomentaList.toVector();
      m_yGaussianPrimitiveAngularMomenta=yGaussianPrimitiveAngularMomentaList.toVector();
      m_zGaussianPrimitiveAngularMomenta=zGaussianPrimitiveAngularMomentaList.toVector();
      m_gaussianPrimitiveExponentCoefficients=gaussianPrimitiveExponentCoefficientsList.toVector();

      QVariant molecularOrbitalOccupationNumbersVariant = mol->property( "QTAIMMolecularOrbitalOccupationNumbers" );
      QVariant molecularOrbitalEigenvaluesVariant = mol->property( "QTAIMMolecularOrbitalEigenvalues" );
      QVariant molecularOrbitalCoefficientsVariant = mol->property( "QTAIMMolecularOrbitalCoefficients" );
      QVariantList molecularOrbitalOccupationNumbersVariantList = molecularOrbitalOccupationNumbersVariant.toList();
      QVariantList molecularOrbitalEigenvaluesVariantList = molecularOrbitalEigenvaluesVariant.toList();
      QVariantList molecularOrbitalCoefficientsVariantList = molecularOrbitalCoefficientsVariant.toList();
      QList<qreal> molecularOrbitalOccupationNumbersList;
      QList<qreal> molecularOrbitalEigenvaluesList;
      QList<qreal> molecularOrbitalCoefficientsList;

      for( qint64 m=0; m < m_numberOfMolecularOrbitals ; ++m )
      {
        molecularOrbitalOccupationNumbersList.append(molecularOrbitalOccupationNumbersVariantList.at(m).toReal());
        molecularOrbitalEigenvaluesList.append(molecularOrbitalEigenvaluesVariantList.at(m).toReal());
      }

      for( qint64 i=0; i < (m_numberOfMolecularOrbitals * m_numberOfGaussianPrimitives) ; ++i)
      {
        molecularOrbitalCoefficientsList.append(molecularOrbitalCoefficientsVariantList.at(i).toReal());
      }

      m_molecularOrbitalOccupationNumbers=molecularOrbitalOccupationNumbersList.toVector();
      m_molecularOrbitalEigenvalues=molecularOrbitalEigenvaluesList.toVector();
      m_molecularOrbitalCoefficients=molecularOrbitalCoefficientsList.toVector();

      QVariant totalEnergyVariant = mol->property("QTAIMTotalEnergy");
      QVariant virialRatioVariant = mol->property("QTAIMVirialRatio");

      m_totalEnergy=totalEnergyVariant.toReal();
      m_virialRatio=virialRatioVariant.toReal();

    }

    return true;
  }
Example #5
0
/** \fn RemoteGetFreeSpace(void)
 *  \brief Returns total and used space in kilobytes for each backend.
 */
QVector<FileSystemInfo> RemoteGetFreeSpace(void)
{
    QList<FileSystemInfo> fsInfos = FileSystemInfo::RemoteGetInfo();
    return fsInfos.toVector();
}
Example #6
0
//Load TSM file
GLC_World GLWidget::loadTSMFile( const QString &filename )
{
	RhBuilderPtr reader = makePtr<RhBuilder>(filename.toStdString());
	TSplinePtr spline = reader->findTSpline();

	GLC_World w;

	IndexList face;
	QList<float> vertex;
	QList<float> normal;

	TTessellator tessellator(spline);

	TImagePtr image = spline->getTImage();

	// Go through all the faces in TImage and create abjects 
	TFacVIterator fiter = image->faceIteratorBegin();
	for (;fiter!=image->faceIteratorEnd();fiter++)
	{
		TFacePtr tface = *fiter;

		TriMeshPtr trimesh = tessellator.interpolateFace(tface);

		P3dVIterator piter = trimesh->pointIteratorBegin();
		for (piter;piter!=trimesh->pointIteratorEnd();piter++)
		{
			vertex.push_back((*piter)->x());
			vertex.push_back((*piter)->y());
			vertex.push_back((*piter)->z());
		}

		N3dVIterator niter = trimesh->normalIteratorBegin();
		for (;niter!=trimesh->normalIteratorEnd();niter++)
		{
			normal.push_back((*niter)->i());
			normal.push_back((*niter)->j());
			normal.push_back((*niter)->k());
		}

		TriVIterator titer = trimesh->triangleIteratorBegin();
		for (;titer!=trimesh->triangleIteratorEnd();titer++)
		{
			face.push_back((*titer)->point_indices[0]);
			face.push_back((*titer)->point_indices[1]);
			face.push_back((*titer)->point_indices[2]);
		}

		GLC_Mesh* glc_mesh = new GLC_Mesh();
		glc_mesh->addTriangles(0,face);
		face.clear();
		glc_mesh->addVertice(vertex.toVector());
		vertex.clear();
		glc_mesh->addNormals(normal.toVector());
		normal.clear();
		glc_mesh->finish();

		GLC_3DRep *rep = new GLC_3DRep(glc_mesh);
		glc_mesh = NULL;
		
		// Set the material 
		GLC_Material* pCurrentMat= NULL;
		pCurrentMat= rep->geomAt(0)->firstMaterial();
		pCurrentMat->setAmbientColor(Qt::gray);
		pCurrentMat->setDiffuseColor(Qt::gray);

		// Add objects (faces) to the world collection 
		w.collection()->add(*rep);
	}
	return w;
}
void ExoplanetsDialog::drawDiagram()
{
	int currentAxisX = ui->comboAxisX->currentData(Qt::UserRole).toInt();
	QString currentAxisXString = ui->comboAxisX->currentText();
	int currentAxisY = ui->comboAxisY->currentData(Qt::UserRole).toInt();
	QString currentAxisYString = ui->comboAxisY->currentText();

	QList<double> aX = ep->getExoplanetsData(currentAxisX), aY = ep->getExoplanetsData(currentAxisY);
	QVector<double> x = aX.toVector(), y = aY.toVector();

	double minX, minY, maxX, maxY;
	minX = maxX = aX.first();
	minY = maxY = aY.first();

	for (auto temp : aX)
	{
		if(maxX < temp) maxX = temp;
		if(minX > temp) minX = temp;
	}
	for (auto temp : aY)
	{
		if(maxY < temp) maxY = temp;
		if(minY > temp) minY = temp;
	}

	if (!ui->minX->text().isEmpty())
		minX = ui->minX->text().toDouble();

	if (!ui->maxX->text().isEmpty())
		maxX = ui->maxX->text().toDouble();

	if (!ui->minY->text().isEmpty())
		minY = ui->minY->text().toDouble();

	if (!ui->maxY->text().isEmpty())
		maxY = ui->maxY->text().toDouble();

	ui->customPlot->addGraph();	
	ui->customPlot->graph(0)->setData(x, y);
	ui->customPlot->graph(0)->setPen(QPen(Qt::blue));
	ui->customPlot->graph(0)->setLineStyle(QCPGraph::lsNone);
	ui->customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 4));
	ui->customPlot->graph(0)->rescaleAxes(true);
	ui->customPlot->xAxis->setLabel(currentAxisXString);
	ui->customPlot->yAxis->setLabel(currentAxisYString);

	ui->customPlot->xAxis->setRange(minX, maxX);
	if (ui->checkBoxLogX->isChecked())
	{
		ui->customPlot->xAxis->setScaleType(QCPAxis::stLogarithmic);
		ui->customPlot->xAxis->setScaleLogBase(10);
	}
	else
		ui->customPlot->xAxis->setScaleType(QCPAxis::stLinear);

	ui->customPlot->yAxis->setRange(minY, maxY);
	if (ui->checkBoxLogY->isChecked())
	{
		ui->customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic);
		ui->customPlot->yAxis->setScaleLogBase(10);
	}
	else
		ui->customPlot->yAxis->setScaleType(QCPAxis::stLinear);

	ui->customPlot->replot();
}