Example #1
0
std::vector<T> LocalDomainAccessStore::deserializeEnumList(const QByteArray& serializedEnumList)
{
    // Deserialize the blob into a std::vector
    QList<int> temp;
    QDataStream stream(serializedEnumList);
    stream >> temp;

    return util::convertIntListToEnumList<T>(temp.toVector().toStdVector());
}
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
//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();
}