// Method reads a line-segment-element from Ideas univ. file (801)
bool
InputIdeasWF::readLine(Body* body, char* buffer)
{
  static Point3 p1, p2;

  // First read Record-3 away.
  // (it is : 1 1 and doesn't contain useful info)
  readFileLine(infile, buffer);

  // Next read the two vertices from infile.

  // -first vertex-point
  readFileLine(infile,buffer);
  readPoint(buffer, p1);

  // -second vertex-point
  readFileLine(infile,buffer);
  readPoint(buffer, p2);

  int body_layer = 0;

  // Create a new 2D element into the body
  createBodyElement2D(body, body_layer, p1, p2);

  return true;
}
Beispiel #2
0
bool NSParser::readPointOrVar(Symbol* symbol, VariableList& variables, Tools::RPoint &point)
{
	bool result = false;
	if (symbol->type == NON_TERMINAL)
	{
		result = true;
		if (symbol->symbolIndex == SYM_POINT)
			point = readPoint(symbol);
		else if (symbol->symbolIndex == SYM_FIXED_POINT)
			point = readFixedPoint(symbol);
		else if (symbol->symbolIndex == SYM_VAR)
			result = readPointVar(symbol, variables, point);
		else //SYM_POINT_OR_VAR
		{
			NonTerminal* nt = static_cast<NonTerminal*>(symbol);
			switch(nt->ruleIndex)
			{
				case PROD_POINT_OR_VAR:
					point = readPoint(searchChild(symbol, SYM_POINT));
					break;
				case PROD_POINT_OR_VAR2:
					result = readPointVar(symbol, variables, point);
					break;
				default:
					result = false;
					break;
			}
		}
	}

	return result;
}
Beispiel #3
0
bool TextLine::readProperties(const QDomElement& e)
      {
      const QString& tag(e.tagName());
      const QString& text(e.text());

      if (tag == "beginHookHeight") {
            _beginHookHeight = Spatium(text.toDouble());
            _beginHook = true;
            }
      else if (tag == "beginHookType")
            _beginHookType = HookType(text.toInt());
      else if (tag == "endHookHeight" || tag == "hookHeight") { // hookHeight is obsolete
            _endHookHeight = Spatium(text.toDouble());
            _endHook = true;
            }
      else if (tag == "endHookType")
            _endHookType = HookType(text.toInt());
      else if (tag == "hookUp")           // obsolete
            _endHookHeight *= qreal(-1.0);
      else if (tag == "beginSymbol" || tag == "symbol")     // "symbol" is obsolete
            _beginSymbol = text[0].isNumber() ? SymId(text.toInt()) : Sym::name2id(text);
      else if (tag == "continueSymbol")
            _continueSymbol = text[0].isNumber() ? SymId(text.toInt()) : Sym::name2id(text);
      else if (tag == "endSymbol")
            _endSymbol = text[0].isNumber() ? SymId(text.toInt()) : Sym::name2id(text);
      else if (tag == "beginSymbolOffset")
            _beginSymbolOffset = readPoint(e);
      else if (tag == "continueSymbolOffset")
            _continueSymbolOffset = readPoint(e);
      else if (tag == "endSymbolOffset")
            _endSymbolOffset = readPoint(e);
      else if (tag == "lineWidth")
            _lineWidth = Spatium(text.toDouble());
      else if (tag == "lineStyle")
            _lineStyle = Qt::PenStyle(text.toInt());
      else if (tag == "beginTextPlace")
            _beginTextPlace = readPlacement(e);
      else if (tag == "continueTextPlace")
            _continueTextPlace = readPlacement(e);
      else if (tag == "lineColor")
            _lineColor = readColor(e);
      else if (tag == "beginText") {
            _beginText = new Text(score());
            _beginText->setParent(this);
            _beginText->read(e);
            }
      else if (tag == "continueText") {
            _continueText = new Text(score());
            _continueText->setParent(this);
            _continueText->read(e);
            }
      else if (!SLine::readProperties(e)) {
            qDebug(" ==readSLineProps: failed");
            return false;
            }
      return true;
      }
Line *JsonFileReader::readLine(const QJsonObject &l)
{
    Line *line = new Line();

    line->setP1(readPoint(l["P1"].toObject()));
    line->setP2(readPoint(l["P2"].toObject()));
    line->setLineThickness(l["LineThickness"].toInt());
    line->setLineColor(readColor(l["LineColor"].toObject()));

    return line;
}
I_Object* SceneSettingReader::readTriangle()
{
    settings_.beginGroup("point1");
    const auto point1 = readPoint();
    settings_.endGroup();
    settings_.beginGroup("point2");
    const auto point2 = readPoint();
    settings_.endGroup();
    settings_.beginGroup("point3");
    const auto point3 = readPoint();
    settings_.endGroup();

    return new Triangle(point1, point2, point3, readMaterial());
}
Beispiel #6
0
int main() {
  std::string line;
  while (true) {
    Point a, b, c;
    if (!readPoint(a)) break;
    if (!readPoint(b)) break;
    if (!readPoint(c)) break;

    double av = angle(b, a, c);
    double bv = angle(a, b, c);
    double cv = angle(a, c, b);
    int res = smallestN(av, bv, cv);
    if (res == -1) assert(false);
    std::cout << res << "\n";
  }
}
void JsonFileReader::readShape(Shape *s, const QJsonObject &obj)
{
    s->setPosition(readPoint(obj["Position"].toObject()));
    s->setFillColor(readColor(obj["FillColor"].toObject()));
    s->setLineColor(readColor(obj["LineColor"].toObject()));
    s->setLineThickness(obj["LineThickness"].toInt());
}
Point3D SceneSettingReader::cameraLocation()
{
    settings_.beginGroup(CAMERA_LOCATION_GROUP);
    const auto cameraLocation = readPoint();
    settings_.endGroup();
    return cameraLocation;
}
Beispiel #9
0
void SlurSegment::read(const QDomElement& de)
      {
      for (QDomElement e = de.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
            const QString& tag(e.tagName());
            if (tag == "o1")
                  ups[GRIP_START].off = readPoint(e);
            else if (tag == "o2")
                  ups[GRIP_BEZIER1].off = readPoint(e);
            else if (tag == "o3")
                  ups[GRIP_BEZIER2].off = readPoint(e);
            else if (tag == "o4")
                  ups[GRIP_END].off = readPoint(e);
            else if (!Element::readProperties(e))
                  domError(e);
            }
      }
Beispiel #10
0
void jcz::XmlParser::readPoints(QIODevice * f, QList<XMLTile> & tiles)
{
	f->open(QIODevice::ReadOnly);
	QXmlStreamReader xml(f);

	xml.readNextStartElement();
	if (xml.name() != "points")
		qWarning() << "unknown element:" << xml.name();
	else
	{
		while (xml.readNextStartElement())
		{
			Q_ASSERT(xml.tokenType() == QXmlStreamReader::StartElement);
			if (xml.name() == "point")
			{
				readPoint(xml, tiles);
			}
			else
				qWarning() << "unknown element:" << xml.name();
		}
		if (xml.hasError())
		{
			qWarning() << xml.errorString();
			Q_ASSERT(false);
		}
	}

	f->close();
}
// Line entity (Type 110)
bool
InputIges::read_110(IgesDirectoryEntry* de, bool check_only_status)
{
  bool result = true;

  int i,j;
  int int_fld;
  char chr_fld;

  static Point3 points[2];

  locateParamEntry(de);

  //-Read one data-line
  readDataLine(lineBuffer, dataBuffer);
  istrstream* data_line = new istrstream(dataBuffer);

  //-Read two points
  *data_line >> int_fld >> chr_fld; // Entity-id

  for(i = 0; i < 2; i++) {
    readPoint(data_line, points[i]);
  }

  int body_layer = 0;
  createBodyElement2D(de->body, body_layer, points[0], points[1]);

  return result;
}
Beispiel #12
0
void GameModule::loadActions(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadActions()");

	s.seek(0x180);
	_actionsCount = s.readUint32LE();
	uint32 offs = s.readUint32LE();
	_actions = new Action[_actionsCount];
	for (int i = 0; i < _actionsCount; ++i) {
		s.seek(offs + i * 72);
		debug(0, "Action(%d) offs: %08X", i, offs + i * 72);
		_actions[i].conditions = readConditions(s);
		for (int j = 0; j < 8; ++j) {
			_actions[i].results.actionResults[j].kind = s.readByte();
			_actions[i].results.actionResults[j].value1 = s.readByte();
			_actions[i].results.actionResults[j].value2 = s.readUint16LE();
		}
		const int actionListCount = s.readUint32LE();
		const uint32 actionListOffs = s.readUint32LE();
		s.seek(actionListOffs);
		for (int j = 0; j < actionListCount; ++j) {
			ActionCommand actionCommand;
			actionCommand.cmd = s.readUint16LE();
			actionCommand.sceneObjectIndex = s.readUint16LE();
			actionCommand.timeStamp = s.readUint32LE();
			actionCommand.walkDest = readPoint(s);
			actionCommand.param = s.readUint32LE();
			_actions[i].actionCommands.push_back(actionCommand);
		}
	}
}
I_Object* SceneSettingReader::readSphere()
{
    settings_.beginGroup("center");
    const auto center = readPoint();
    settings_.endGroup();
    const double radius = settings_.value("radius").toDouble();
    return new Sphere(center, radius, readMaterial());
}
std::vector<point> readInputData(std::string line)
{
	size_t pos{0};
	std::vector<point> points;
	while (pos != std::string::npos) {
		pos = line.find_first_of(",|");
		std::string substr = line.substr(0, pos);
		points.push_back(readPoint(substr));
		line = line.substr(pos+1, line.length()-pos);
	}
	return points;
}
Beispiel #15
0
void GameModule::loadCameraInits(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadCameraInits()");

	s.seek(0x20);
	for (int i = 0; i < kCameraInitsCount; ++i) {
		CameraInit &cameraInit = _cameraInits[i];
		cameraInit.cameraPos = readPoint(s);
		for (int j = 0; j < 8; ++j)
			cameraInit.cameraLinks[j] = s.readByte();
		for (int j = 0; j < 8; ++j)
			cameraInit.rects[j] = readRect(s);
	}
}
Beispiel #16
0
bool LineSegment::readProperties(const QDomElement& e)
      {
      const QString& tag(e.tagName());
      if (tag == "subtype")
            setSubtype(SpannerSegmentType(e.text().toInt()));
      else if (tag == "off1")       // obsolete
            setUserOff(readPoint(e) * spatium());
      else if (tag == "off2")
            setUserOff2(readPoint(e) * spatium());
      else if (tag == "pos") {
            if (score()->mscVersion() > 114) {
                  qreal _spatium = spatium();
                  setUserOff(QPointF());
                  setReadPos(readPoint(e) * _spatium);
                  }
            }
      else if (!Element::readProperties(e)) {
            domError(e);
            return false;
            }
      return true;
      }
I_Object* SceneSettingReader::readModel()
{
    const QString filename = settings_.value("filename").toString();
    settings_.beginGroup("center");
    const Point3D center = readPoint();
    settings_.endGroup();
    const double maxDimension = settings_.value("maxDimension").toDouble();
    const double xRotationDegree = settings_.value("xRotation").toDouble();
    const double yRotationDegree = settings_.value("yRotation").toDouble();
    const double zRotationDegree = settings_.value("zRotation").toDouble();
    ModelLoader model(filename, center, maxDimension,
        xRotationDegree, yRotationDegree, zRotationDegree, readMaterial());
    return new BoundingBoxObject(model.triangles(), model.maxDimensions());
}
Beispiel #18
0
// Reads in the data set points from <filename> in the array
// <dataSetPoints>. Each point get a unique number in the field
// <index> to be easily indentifiable.
void readDataSetFromFile(char *filename){
  FILE *f = fopen(filename, "rt");
  FAILIF(f == NULL);
  
  //fscanf(f, "%d %d ", &nPoints, &pointsDimension);
  //FSCANF_DOUBLE(f, &thresholdR);
  //FSCANF_DOUBLE(f, &successProbability);
  //fscanf(f, "\n");
  FAILIF(NULL == (dataSetPoints = (PPointT*)MALLOC(nPoints * sizeof(PPointT))));
  for(IntT i = 0; i < nPoints; i++){
    dataSetPoints[i] = readPoint(f);
    dataSetPoints[i]->index = i;
  }
}
Beispiel #19
0
bool classifyFuturePoints(double& a,
												  double& b,
												  double& c,
													point& c1,
													point& c2)
{
	point p;
	while(readPoint(p,std::cin,false) && !std::cin.eof())
	{
		double val = a*p.x+b*p.y+c;
		if (SGN(val) == SGN(a*c1.x+b*c1.y+c)) std::cout << "1" << std::endl;
		else std::cout << "2" << std::endl;
	}
	return true;
}
Beispiel #20
0
static char*
arrowEnd (char* s0, char* pfx, int* fp, double* xp, double* yp)
{
    char* s = skipWS(s0);

    if (strncmp(s,pfx,2)) return s;
    s += 2;  /* skip prefix */
    s = readPoint (s, xp, yp);
    if (s == NULL) {
	fprintf (stderr, "Illegal spline end: %s\n", s0);
	exit (1);
    }
    *fp = 1;
    return s;
}
// Method reads one vertex from input-string *s*.
BodyElement*
InputIges::readVertex(istrstream*& data_line)
{
  static Point3 point;
  static GcPoint gpoint;

  if ( !readPoint(data_line, point) )
    return NULL;

  gpoint.setPosit(point[0], point[1], point[2]);

  // Create vertex from the point in the input file.
  BodyElement* vertex = new BodyElement1D(&gpoint);

  return vertex;
}
void RigidAlignment::setup(const char *landmarkDir, vector<char *> landmarkList, const char *sphere)
{
	m_sphere = new Mesh();
	m_sphere->openFile(sphere);

	m_nSubj = landmarkList.size();
	for (int i = 0; i < m_nSubj; i++)
	{
		char fullpath[1024];
		sprintf(fullpath, "%s/%s", landmarkDir, landmarkList[i]);
		cout << "[" << i << "] " << landmarkList[i] << endl;
		readPoint(fullpath);
		m_filename.push_back(landmarkList[i]);
	}

	// rotation angle
	m_rot = new float[m_nSubj * 3];
	memset(m_rot, 0, sizeof(float) * m_nSubj * 3);
	m_nLM = m_point[0].size();
	
	// workspace
	fpoint = new float[m_nSubj * m_nLM * 3];
	fmean = new float[m_nLM * 3];
	faxis = new float[m_nSubj * 3];

	// axis
	memset(faxis, 0, sizeof(float) * m_nSubj * 3);
	for (int i = 0; i < m_nSubj; i++)
	{
		float *axis = &faxis[i * 3];
		for (int j = 0; j < m_nLM; j++)
		{
			float *p = &fpoint[(i * m_nLM + j) * 3];
			int id = m_point[i][j];
			memcpy(p, m_sphere->vertex(id)->fv(), sizeof(float) * 3);
			for (int k = 0; k < 3; k++) axis[k] += p[k];
		}
		
		// axis
		float norm = axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2];
		norm = sqrt(norm);
		for (int k = 0; k < 3; k++) axis[k] /= norm;
	}
}
std::list<Light> SceneSettingReader::readLights()
{
    std::list<Light> lights;
    settings_.beginGroup(LIGHTS_GROUP);
    const int size = settings_.beginReadArray("lights");
    for (int i = 0; i < size; ++i)
    {
        settings_.setArrayIndex(i);
        settings_.beginGroup("diffuse");
        const Color diffuse = readColor();
        settings_.endGroup();
        settings_.beginGroup("specular");
        const Color specular = readColor();
        settings_.endGroup();
        lights.push_back(Light(readPoint(), diffuse, specular));
    }
    settings_.endArray();
    settings_.endGroup();
    return lights;
}
Beispiel #24
0
static void
emitSpline (char* s, FILE* outFile, int ix)
{
    double sx, sy, ex, ey;
    int sarrow = 0;
    int earrow = 0;

    s = arrowEnd (s, "e,", &earrow, &ex, &ey); 
    s = arrowEnd (s, "s,", &sarrow, &sx, &sy); 
    indent (ix, outFile);
    fprintf (outFile, "Line [\n");
    if (sarrow)
	emitPoint (sx, sy, outFile, ix+1);
    while ((s = readPoint (s, &sx, &sy)))
	emitPoint (sx, sy, outFile, ix+1);
    if (earrow)
	emitPoint (ex, ey, outFile, ix+1);
    indent (ix, outFile);
    fprintf (outFile, "]\n");

}
Beispiel #25
0
/*
  The main entry to LSH package. Depending on the command line
  parameters, the function computes the R-NN data structure optimal
  parameters and/or construct the R-NN data structure and runs the
  queries on the data structure.
 */
int main(int nargs, char **args){
  if(nargs < 9){
    usage(args[0]);
    exit(1);
  }

  //initializeLSHGlobal();

  // Parse part of the command-line parameters.
  nPoints = atoi(args[1]);
  IntT nQueries = atoi(args[2]);
  pointsDimension = atoi(args[3]);
  successProbability = atof(args[4]);
  char* endPtr[1];
  RealT thresholdR = strtod(args[5], endPtr);
  if (thresholdR == 0 || endPtr[1] == args[5]){
    // The value for R is not specified, instead there is a file
    // specifying multiple R's.
    thresholdR = 0;

    // Read in the file
    FILE *radiiFile = fopen(args[5], "rt");
    FAILIF(radiiFile == NULL);
    fscanf(radiiFile, "%d\n", &nRadii);
    ASSERT(nRadii > 0);
    FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    FAILIF(NULL == (memRatiosForNNStructs = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    for(IntT i = 0; i < nRadii; i++){
      FSCANF_REAL(radiiFile, &listOfRadii[i]);
      ASSERT(listOfRadii[i] > 0);
      FSCANF_REAL(radiiFile, &memRatiosForNNStructs[i]);
      ASSERT(memRatiosForNNStructs[i] > 0);
    }
  }else{
    nRadii = 1;
    FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    FAILIF(NULL == (memRatiosForNNStructs = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    listOfRadii[0] = thresholdR;
    memRatiosForNNStructs[0] = 1;
  }
  DPRINTF("No. radii: %d\n", nRadii);
  //thresholdR = atof(args[5]);
  availableTotalMemory = atoll(args[8]);

  if (nPoints > MAX_N_POINTS) { // 104w points
    printf("Error: the structure supports at most %d points (%d were specified).\n", MAX_N_POINTS, nPoints);
    fprintf(ERROR_OUTPUT, "Error: the structure supports at most %d points (%d were specified).\n", MAX_N_POINTS, nPoints);
    exit(1);
  }

  readDataSetFromFile(args[6]); // read points into data structure
  DPRINTF("Allocated memory (after reading data set): %lld\n", totalAllocatedMemory);

  Int32T nSampleQueries = N_SAMPLE_QUERY_POINTS;
  PPointT sampleQueries[nSampleQueries];
  Int32T sampleQBoundaryIndeces[nSampleQueries];
  if ((nargs < 9) || (strcmp("-c", args[9]) == 0)){
    // In this cases, we need to generate a sample query set for
    // computing the optimal parameters.

    // Generate a sample query set.
    FILE *queryFile = fopen(args[7], "rt");
    if (strcmp(args[7], ".") == 0 || queryFile == NULL || nQueries <= 0){
      // Choose several data set points for the sample query points.
      for(IntT i = 0; i < nSampleQueries; i++){
	sampleQueries[i] = dataSetPoints[genRandomInt(0, nPoints - 1)];
      }
    }else{
      // Choose several actual query points for the sample query points.
      nSampleQueries = MIN(nSampleQueries, nQueries);
      Int32T sampleIndeces[nSampleQueries];
      for(IntT i = 0; i < nSampleQueries; i++){
	sampleIndeces[i] = genRandomInt(0, nQueries - 1);
      }
      qsort(sampleIndeces, nSampleQueries, sizeof(*sampleIndeces), compareInt32T);
      //printIntVector("sampleIndeces: ", nSampleQueries, sampleIndeces);
      Int32T j = 0;
      for(Int32T i = 0; i < nQueries; i++){
	if (i == sampleIndeces[j]){
	  sampleQueries[j] = readPoint(queryFile);
	  j++;
	  while (i == sampleIndeces[j]){
	    sampleQueries[j] = sampleQueries[j - 1];
	    j++;
	  }
	}else{
	  fscanf(queryFile, "%[^\n]", sBuffer);
	  fscanf(queryFile, "\n");
	}
      }
      nSampleQueries = j;
      fclose(queryFile);
    }

    // Compute the array sampleQBoundaryIndeces that specifies how to
    // segregate the sample query points according to their distance
    // to NN.
    sortQueryPointsByRadii(pointsDimension,
			   nSampleQueries,
			   sampleQueries,
			   nPoints,
			   dataSetPoints,
			   nRadii,
			   listOfRadii,
			   sampleQBoundaryIndeces);
  }

  RNNParametersT *algParameters = NULL;
  PRNearNeighborStructT *nnStructs = NULL;
  if (nargs > 9) {
    // Additional command-line parameter is specified.
    if (strcmp("-c", args[9]) == 0) {
      // Only compute the R-NN DS parameters and output them to stdout.
      
      printf("%d\n", nRadii);
      transformMemRatios();
      for(IntT i = 0; i < nRadii; i++){
	// which sample queries to use
	Int32T segregatedQStart = (i == 0) ? 0 : sampleQBoundaryIndeces[i - 1];
	Int32T segregatedQNumber = nSampleQueries - segregatedQStart;
	if (segregatedQNumber == 0) {
	  // XXX: not the right answer
	  segregatedQNumber = nSampleQueries;
	  segregatedQStart = 0;
	}
	ASSERT(segregatedQStart < nSampleQueries);
	ASSERT(segregatedQStart >= 0);
	ASSERT(segregatedQStart + segregatedQNumber <= nSampleQueries);
	ASSERT(segregatedQNumber >= 0);
	RNNParametersT optParameters = computeOptimalParameters(listOfRadii[i],
								successProbability,
								nPoints,
								pointsDimension,
								dataSetPoints,
								segregatedQNumber,
								sampleQueries + segregatedQStart,
								(MemVarT)((availableTotalMemory - totalAllocatedMemory) * memRatiosForNNStructs[i]));
	printRNNParameters(stdout, optParameters);
      }
      exit(0);
    } else if (strcmp("-p", args[9]) == 0) {
      // Read the R-NN DS parameters from the given file and run the
      // queries on the constructed data structure.
      if (nargs < 10){
	usage(args[0]);
	exit(1);
      }
      FILE *pFile = fopen(args[10], "rt");
      FAILIFWR(pFile == NULL, "Could not open the params file.");
      fscanf(pFile, "%d\n", &nRadii);
      DPRINTF1("Using the following R-NN DS parameters:\n");
      DPRINTF("N radii = %d\n", nRadii);
      FAILIF(NULL == (nnStructs = (PRNearNeighborStructT*)MALLOC(nRadii * sizeof(PRNearNeighborStructT))));
      FAILIF(NULL == (algParameters = (RNNParametersT*)MALLOC(nRadii * sizeof(RNNParametersT))));
      for(IntT i = 0; i < nRadii; i++){
	algParameters[i] = readRNNParameters(pFile);
	printRNNParameters(stderr, algParameters[i]);
	nnStructs[i] = initLSH_WithDataSet(algParameters[i], nPoints, dataSetPoints);
      }

      pointsDimension = algParameters[0].dimension;
      FREE(listOfRadii);
      FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT))));
      for(IntT i = 0; i < nRadii; i++){
	listOfRadii[i] = algParameters[i].parameterR;
      }
    } else{
      // Wrong option.
      usage(args[0]);
      exit(1);
    }
  } else {
    FAILIF(NULL == (nnStructs = (PRNearNeighborStructT*)MALLOC(nRadii * sizeof(PRNearNeighborStructT))));
    // Determine the R-NN DS parameters, construct the DS and run the queries.
    transformMemRatios();
    for(IntT i = 0; i < nRadii; i++){
      // XXX: segregate the sample queries...
      nnStructs[i] = initSelfTunedRNearNeighborWithDataSet(listOfRadii[i], 
							   successProbability, 
							   nPoints, 
							   pointsDimension, 
							   dataSetPoints, 
							   nSampleQueries, 
							   sampleQueries, 
							   (MemVarT)((availableTotalMemory - totalAllocatedMemory) * memRatiosForNNStructs[i]));
    }
  }

  DPRINTF1("X\n");

  IntT resultSize = nPoints;
  PPointT *result = (PPointT*)MALLOC(resultSize * sizeof(*result));
  PPointT queryPoint;
  FAILIF(NULL == (queryPoint = (PPointT)MALLOC(sizeof(PointT))));
  FAILIF(NULL == (queryPoint->coordinates = (RealT*)MALLOC(pointsDimension * sizeof(RealT))));

  FILE *queryFile = fopen(args[7], "rt");
  FAILIF(queryFile == NULL);
  TimeVarT meanQueryTime = 0;
  PPointAndRealTStructT *distToNN = NULL;
  for(IntT i = 0; i < nQueries; i++){

    RealT sqrLength = 0;
    // read in the query point.
    for(IntT d = 0; d < pointsDimension; d++){
      FSCANF_REAL(queryFile, &(queryPoint->coordinates[d]));
      sqrLength += SQR(queryPoint->coordinates[d]);
    }
    queryPoint->sqrLength = sqrLength;
    //printRealVector("Query: ", pointsDimension, queryPoint->coordinates);

    // get the near neighbors.
    IntT nNNs = 0;
    for(IntT r = 0; r < nRadii; r++){
      nNNs = getRNearNeighbors(nnStructs[r], queryPoint, result, resultSize);
      printf("Total time for R-NN query at radius %0.6lf (radius no. %d):\t%0.6lf\n", (double)(listOfRadii[r]), r, timeRNNQuery);
      meanQueryTime += timeRNNQuery;

      if (nNNs > 0){
	printf("Query point %d: found %d NNs at distance %0.6lf (%dth radius). First %d NNs are:\n", i, nNNs, (double)(listOfRadii[r]), r, MIN(nNNs, MAX_REPORTED_POINTS));
	
	// compute the distances to the found NN, and sort according to the distance
	FAILIF(NULL == (distToNN = (PPointAndRealTStructT*)REALLOC(distToNN, nNNs * sizeof(*distToNN))));
	for(IntT p = 0; p < nNNs; p++){
	  distToNN[p].ppoint = result[p];
	  distToNN[p].real = distance(pointsDimension, queryPoint, result[p]);
	}
	qsort(distToNN, nNNs, sizeof(*distToNN), comparePPointAndRealTStructT);

	// Print the points
	for(IntT j = 0; j < MIN(nNNs, MAX_REPORTED_POINTS); j++){
	  ASSERT(distToNN[j].ppoint != NULL);
	  printf("%09d\tDistance:%0.6lf\n", distToNN[j].ppoint->index, distToNN[j].real);
	  CR_ASSERT(distToNN[j].real <= listOfRadii[r]);
	  //DPRINTF("Distance: %lf\n", distance(pointsDimension, queryPoint, result[j]));
	  //printRealVector("NN: ", pointsDimension, result[j]->coordinates);
	}
	break;
      }
    }
    if (nNNs == 0){
      printf("Query point %d: no NNs found.\n", i);
    }
  }
  if (nQueries > 0){
    meanQueryTime = meanQueryTime / nQueries;
    printf("Mean query time: %0.6lf\n", (double)meanQueryTime);
  }

  for(IntT i = 0; i < nRadii; i++){
    freePRNearNeighborStruct(nnStructs[i]);
  }
  // XXX: should ideally free the other stuff as well.


  return 0;
}
Beispiel #26
0
QRectF NSParser::readFixedRect(Symbol* symbol, VariableList& variables)
{
	QRectF r(0,0,1,1);
	Tools::RPoint center;
	bool definedByCenter = false;
	double radius = 0;
	int nbParamRead = 0;
	if (symbol->type == NON_TERMINAL)
	{
		NonTerminal* nt = static_cast<NonTerminal*>(symbol);
		for(Symbol* child: nt->children)
		{
			switch(child->symbolIndex)
			{
				case SYM_NUM:
				{
					double value = readNum(child);
					if (definedByCenter)
						radius = value;
					else if (nbParamRead == 0)
						r.setX(value);
					else if (nbParamRead == 1)
						r.setY(value);
					else if (nbParamRead == 2)
						r.setWidth(value);
					else
						r.setHeight(value);
					++nbParamRead;
					break;
				}
				case SYM_POINT:
				case SYM_FIXED_POINT:
				{
					definedByCenter = true;
					center = readPoint(child);
					break;
				}
				case SYM_VAR:
				{
					QString name = readVar(child);
					if (variables.contains(name))
					{
						DeclaredVariable& var = variables[name];
						if (var.isPoint())
						{
							center = var.toPoint();
							definedByCenter = true;
						}
						else
							addError(NSParsingError::invalidVariableTypeError(name, "point", child));
					}
					else
						addError(NSParsingError::undeclaredVariableError(name, child));


					break;
				}
			}
		}
	}

	if (definedByCenter)
	{
		r.setWidth(radius * 2.0);
		r.setHeight(radius * 2.0);
		r.moveCenter(center.toQPointF());
	}

	return r;
}
Beispiel #27
0
void dibSHP::procesFile(Document_Interface *doc)
{
    int num_ent, st;
    double min_bound[4], max_bound[4];

    currDoc = doc;

    QFileInfo fi = QFileInfo(fileedit->text());
    if (fi.suffix() != "shp") {
        QMessageBox::critical ( this, "Shapefile", QString(tr("The file %1 not have extension .shp")).arg(fileedit->text()) );
        return;
    }

    if (!fi.exists() ) {
        QMessageBox::critical ( this, "Shapefile", QString(tr("The file %1 not exist")).arg(fileedit->text()) );
        return;
    }

    QString file = fi.canonicalFilePath ();

    SHPHandle sh = SHPOpen( file.toLocal8Bit(), "rb" );
    SHPGetInfo( sh, &num_ent, &st, min_bound, max_bound );
    DBFHandle dh = DBFOpen( file.toLocal8Bit(), "rb" );

    if (radiolay1->isChecked()) {
        layerF = -1;
        attdata.layer = currDoc->getCurrentLayer();
    } else {
        layerF = DBFGetFieldIndex( dh, (layerdata->currentText()).toLatin1().data() );
        layerT = DBFGetFieldInfo( dh, layerF, NULL, NULL, NULL );
    }
    if (radiocol1->isChecked())
        colorF = -1;
    else {
        colorF = DBFGetFieldIndex( dh, (colordata->currentText()).toLatin1().data() );
        colorT = DBFGetFieldInfo( dh, colorF, NULL, NULL, NULL );
    }
    if (radioltype1->isChecked())
        ltypeF = -1;
    else {
        ltypeF = DBFGetFieldIndex( dh, (ltypedata->currentText()).toLatin1().data() );
        ltypeT = DBFGetFieldInfo( dh, ltypeF, NULL, NULL, NULL );
    }
    if (radiolwidth1->isChecked())
        lwidthF = -1;
    else {
        lwidthF = DBFGetFieldIndex( dh, (lwidthdata->currentText()).toLatin1().data() );
        lwidthT = DBFGetFieldInfo( dh, lwidthF, NULL, NULL, NULL );
    }
    if (radiopoint1->isChecked())
        pointF = -1;
    else {
        pointF = DBFGetFieldIndex( dh, (pointdata->currentText()).toLatin1().data() );
        pointT = DBFGetFieldInfo( dh, pointF, NULL, NULL, NULL );
    }

    currlayer =currDoc->getCurrentLayer();
    for( int i = 0; i < num_ent; i++ ) {
        sobject= NULL;
        sobject = SHPReadObject( sh, i );
        if (sobject) {
            switch (sobject->nSHPType) {
            case SHPT_NULL:
                break;
            case SHPT_POINT:
            case SHPT_POINTM: //2d point with measure
            case SHPT_POINTZ: //3d point
                readPoint(dh, i);
                break;
            case SHPT_MULTIPOINT:
            case SHPT_MULTIPOINTM:
            case SHPT_MULTIPOINTZ:
                break;
            case SHPT_ARC:
            case SHPT_ARCM:
            case SHPT_ARCZ:
                readPolyline(dh, i);
                break;
            case SHPT_POLYGON:
            case SHPT_POLYGONM:
            case SHPT_POLYGONZ:
                readPolylineC(dh, i);
            case SHPT_MULTIPATCH:
                readMultiPolyline(dh, i);
            default:
                break;
            }
            SHPDestroyObject(sobject);
        }
    }

    SHPClose( sh );
    DBFClose( dh );
    currDoc->setLayer(currlayer);
}
Beispiel #28
0
bool NSParser::readCallArg(Symbol *symbol, VariableList &variables, NSParser::DeclaredVariable& callArgVariable)
{
	bool result = true;
	switch(symbol->symbolIndex)
	{
		case SYM_VAR:
		{
			QString name = readVar(symbol);
			if (variables.contains(name))
				callArgVariable = variables[name];
			else
			{
				addError(NSParsingError::undeclaredVariableError(name, symbol));
				result = false;
			}
			break;
		}
		case SYM_POINT:
		case SYM_FIXED_POINT:
		{
			Tools::RPoint p = readPoint(symbol);
			callArgVariable = DeclaredVariable::fromPoint(p);
			break;
		}
		case SYM_RECT2:
		case SYM_FIXED_RECT:
		{
			QRectF r = readRect(symbol, variables);
			callArgVariable = DeclaredVariable::fromRect(r);
			break;
		}
		case SYM_SENSOR_IDENTIFIER:
		{
			int type = -1, id = 0;
			readSensorIdentifier(symbol, type, id);
			callArgVariable = DeclaredVariable::fromSensor(id, type);
			break;
		}
		case SYM_PARAMETER_IDENTIFIER:
		{
			int paramId = readSubId(symbol);
			callArgVariable = DeclaredVariable::fromParameter(paramId);
			break;
		}
		case SYM_AX12_IDENTIFIER:
		{
			int ax12Id = readSubId(symbol);
			callArgVariable = DeclaredVariable::fromAx12(ax12Id);
			break;
		}
		case SYM_ACTION2:
		{
			int actionId, param, time;
			readAction(symbol, actionId, param, time);
			callArgVariable = DeclaredVariable::fromAction(actionId, param, time);
			break;
		}
		case SYM_STRING:
		{
			QString str = readString(symbol);
			callArgVariable = DeclaredVariable::fromString(str);
			break;
		}
		case SYM_CALLARG:
		{
			if (symbol->type == NON_TERMINAL)
			{
				result = false;
				NonTerminal* nt = static_cast<NonTerminal*>(symbol);
				for(Symbol* child: nt->children)
				{
					readCallArg(child, variables, callArgVariable);
					if (callArgVariable.isValid())
					{
						result = true;
						break;
					}

				}
			}
		}
	}

	return result;
}
Beispiel #29
0
/*
  The main entry to LSH package. Depending on the command line
  parameters, the function computes the R-NN data structure optimal
  parameters and/or construct the R-NN data structure and runs the
  queries on the data structure.
 */
int main_T(int nargs, char **args)
{


	//先分析参数
	/* 官方lsh文件:10个参数
	1000 9 784 0.9  0.6  mnist1k.dts  mnist1k.q
	bin/LSHMain $nDataSet $nQuerySet $dimension $successProbability "$1" "$2" "$3" $m -c*/


	//算参数	bin/LSHMain 1000 9 784 0.9  "0.6" "mnist1k.dts" "mnist1k.q" 1002000000  -c


	//bin/LSHMain $nDataSet $nQuerySet $dimension $successProbability 1.0 "$1" "$2" $m -p "$3"

	//匹配	bin/LSHMain 1000 9 784 0.9 1.0  "mnist1k.dts" "mnist1k.q" 1002000000  -p  "outputparma.txt"
  if(nargs < 9)
  {
    usage(args[0]);
    exit(1);
  }

  //initializeLSHGlobal();

  // Parse part of the command-line parameters.
  nPoints = atoi(args[1]);
  IntT nQueries = atoi(args[2]);
  pointsDimension = atoi(args[3]);
  successProbability = atof(args[4]);
  char* endPtr[1];
  RealT thresholdR = strtod(args[5], endPtr);//点相邻的距离阈值
  //str-to -double  将字符串转换成浮点数的函数
  //endPtr 接收数字结尾后非字符串字母

  //这个r阈值是什么呢?
  if (thresholdR == 0 || endPtr[1] == args[5])
  {//如果阈值为0,或者第一个字符就不是数字, 
	  //表示是用文件保存的
	  //这大概是用于测试哪个阈值好的
    // The value for R is not specified, instead there is a file
    // specifying multiple R's.
    thresholdR = 0;

    // Read in the file
    FILE *radiiFile = fopen(args[5], "rt");
    FAILIF(radiiFile == NULL);
    fscanf(radiiFile, "%d\n", &nRadii);
    ASSERT(nRadii > 0);
    FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    FAILIF(NULL == (memRatiosForNNStructs = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    for(IntT i = 0; i < nRadii; i++)
	{
      FSCANF_REAL(radiiFile, &listOfRadii[i]);
      ASSERT(listOfRadii[i] > 0);
      FSCANF_REAL(radiiFile, &memRatiosForNNStructs[i]);
      ASSERT(memRatiosForNNStructs[i] > 0);
    }
  }
  else
  {
    nRadii = 1;
    FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    FAILIF(NULL == (memRatiosForNNStructs = (RealT*)MALLOC(nRadii * sizeof(RealT))));
    listOfRadii[0] = thresholdR;
    memRatiosForNNStructs[0] = 1;
  }//对阈值R 和Radiii的处理



  DPRINTF("No. radii: %d\n", nRadii);
  //thresholdR = atof(args[5]);
  availableTotalMemory = atoll(args[8]);//$M表示的是内存空间大小

  if (nPoints > MAX_N_POINTS)
  {
    printf("Error: the structure supports at most %d points (%d were specified).\n", MAX_N_POINTS, nPoints);
    fprintf(ERROR_OUTPUT, "Error: the structure supports at most %d points (%d were specified).\n", MAX_N_POINTS, nPoints);
    exit(1);
  }

  readDataSetFromFile(args[6]);//点读到dataSetPoints

  //这个totalAllocatedMemory初始化为0,但是
  //#define MALLOC(amount) ((amount > 0) ? totalAllocatedMemory += amount, malloc(amount) : NULL)
  //这样,每次申请内存都会统计到了

  DPRINTF("Allocated memory (after reading data set): %lld\n", totalAllocatedMemory);

  Int32T nSampleQueries = N_SAMPLE_QUERY_POINTS;
  PPointT sampleQueries[N_SAMPLE_QUERY_POINTS];
  Int32T sampleQBoundaryIndeces[N_SAMPLE_QUERY_POINTS];
//  PPointT sampleQueries[nSampleQueries];
 // Int32T sampleQBoundaryIndeces[nSampleQueries];
 
  
  if ((nargs <= 9)   ||  (strcmp("-c", args[9]) == 0)    )
  {
    // In this cases, we need to generate a sample query set for
    // computing the optimal parameters.

    // Generate a sample query set.
    FILE *queryFile = fopen(args[7], "rt");
    if (strcmp(args[7], ".") == 0 || queryFile == NULL || nQueries <= 0)
	{//没有查询文件,就用所有点产生随机点
      // Choose several data set points for the sample query points.
		for(IntT i = 0; i < nSampleQueries; i++){
			sampleQueries[i] = dataSetPoints[genRandomInt(0, nPoints - 1)];

	  }
    }
	else
	{
		//从查询文件中选取随机的点,
      // Choose several actual query points for the sample query points.
		  nSampleQueries = MIN(nSampleQueries, nQueries);
		   Int32T sampleIndeces[N_SAMPLE_QUERY_POINTS];
		  //Int32T sampleIndeces[nSampleQueries];
		  for(IntT i = 0; i < nSampleQueries; i++)
		  {
			sampleIndeces[i] = genRandomInt(0, nQueries - 1);
		  }
		  qsort(sampleIndeces, nSampleQueries, sizeof(*sampleIndeces), compareInt32T);
		  //printIntVector("sampleIndeces: ", nSampleQueries, sampleIndeces);
		  Int32T j = 0;
		  for(Int32T i = 0; i < nQueries; i++)
		  {
			  if (i == sampleIndeces[j])
			  {
				  sampleQueries[j] = readPoint(queryFile);
				  j++;
				  while (i == sampleIndeces[j])
				  {
					  sampleQueries[j] = sampleQueries[j - 1];
					  j++;
				  }
			  }else
			  {
				  fscanf(queryFile, "%[^\n]", sBuffer);
				  fscanf(queryFile, "\n");
			  }
		 }
		  nSampleQueries = j;
		  fclose(queryFile);
    }

	//前面那么多,好像就是在申请内存,读文件,读入参数

    // Compute the array sampleQBoundaryIndeces that specifies how to
    // segregate the sample query points according to their distance
    // to NN.
	//采用遍历的方法,计算查询点的最近邻(并且距离小于listOfRadii【nRadii】)
    sortQueryPointsByRadii(pointsDimension,
			   nSampleQueries,
			   sampleQueries,
			   nPoints,
			   dataSetPoints,
			   nRadii,
			   listOfRadii,
			   sampleQBoundaryIndeces);
  }//if ((nargs < 9) || (strcmp("-c", args[9]) == 0))


  RNNParametersT *algParameters = NULL;
  PRNearNeighborStructT *nnStructs = NULL;
  if (nargs > 9) 
  {/* 官方lsh文件:10个参数
bin/LSHMain $nDataSet $nQuerySet $dimension $successProbability "$1" "$2" "$3" $m -c


*/
	     
    // Additional command-line parameter is specified.
    if (strcmp("-c", args[9]) == 0) 	//-c表示参数优化
	{
 // Only compute the R-NN DS parameters and output them to stdout.
      printf("%d\n", nRadii);
      transformMemRatios();
      for(IntT i = 0; i < nRadii; i++)
	  {
		// which sample queries to use
		Int32T segregatedQStart = (i == 0) ? 0 : sampleQBoundaryIndeces[i - 1];
		Int32T segregatedQNumber = nSampleQueries - segregatedQStart;
		if (segregatedQNumber == 0) 
		{
		  // XXX: not the right answer
		  segregatedQNumber = nSampleQueries;
		  segregatedQStart = 0;
		}
		ASSERT(segregatedQStart < nSampleQueries);
		ASSERT(segregatedQStart >= 0);
		ASSERT(segregatedQStart + segregatedQNumber <= nSampleQueries);
		ASSERT(segregatedQNumber >= 0);

		//从文件读取点,然后计算优化后的参数
		RNNParametersT optParameters = computeOptimalParameters(listOfRadii[i],
									successProbability,
									nPoints,
									pointsDimension,
									dataSetPoints,
									segregatedQNumber,
									sampleQueries + segregatedQStart,
/*对内存的约束,就体现在这里,
availableTotalMemory总共的内存(传入) - totalAllocatedMemory(使用mallloc分配的)*1=内存上限

然后(L * nPoints > memoryUpperBound / 12 来约束
*/
									(MemVarT)((availableTotalMemory - totalAllocatedMemory) * memRatiosForNNStructs[i]));
		printRNNParameters(stdout, optParameters);
      }
      exit(0);
    } 
	else if (strcmp("-p", args[9]) == 0) 
	{//-p表示从文件读入参数,然后建立结构体
      // Read the R-NN DS parameters from the given file and run the
      // queries on the constructed data structure.
      if (nargs < 10)
	  {
		  usage(args[0]);
		  exit(1);
      }
      FILE *pFile = fopen(args[10], "rt");
      FAILIFWR(pFile == NULL, "Could not open the params file.");
      fscanf(pFile, "%d\n", &nRadii);
      DPRINTF1("Using the following R-NN DS parameters:\n");
      DPRINTF("N radii = %d\n", nRadii);
      FAILIF(NULL == (nnStructs = (PRNearNeighborStructT*)MALLOC(nRadii * sizeof(PRNearNeighborStructT))));
      FAILIF(NULL == (algParameters = (RNNParametersT*)MALLOC(nRadii * sizeof(RNNParametersT))));
      for(IntT i = 0; i < nRadii; i++)
	  {//默认i=1
		  algParameters[i] = readRNNParameters(pFile);//从文件读参数

		  printRNNParameters(stderr, algParameters[i]);
		  nnStructs[i] = initLSH_WithDataSet(algParameters[i], nPoints, dataSetPoints);
		  //核心
		  //初始化整个数据结构 包括整体+l个hash表 +点映射到桶
	  }

      pointsDimension = algParameters[0].dimension;
      FREE(listOfRadii);
      FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT))));
      for(IntT i = 0; i < nRadii; i++)
	  {
		  listOfRadii[i] = algParameters[i].parameterR;
	  }
    } 
	else
	{
      // Wrong option.
      usage(args[0]);
      exit(1);
    }
  }//if (nargs > 9) 
  else 
  {
    FAILIF(NULL == (nnStructs = (PRNearNeighborStructT*)MALLOC(nRadii * sizeof(PRNearNeighborStructT))));
    // Determine the R-NN DS parameters, construct the DS and run the queries.
    transformMemRatios();
    for(IntT i = 0; i < nRadii; i++)
	{
      // XXX: segregate the sample queries...
		//建立查询结构,自动优化参数
      nnStructs[i] = initSelfTunedRNearNeighborWithDataSet(listOfRadii[i], 
							   successProbability, 
							   nPoints, 
							   pointsDimension, 
							   dataSetPoints, 
							   nSampleQueries, 
							   sampleQueries, 
							   (MemVarT)((availableTotalMemory - totalAllocatedMemory) * memRatiosForNNStructs[i]));
    }
  } // if (nargs <= 9) 



  //上面都是根据不同配置,对参数的优化,建立查询结构

  DPRINTF1("X\n");

  IntT resultSize = nPoints;
  PPointT *result = (PPointT*)MALLOC(resultSize * sizeof(*result));
  PPointT queryPoint;
  FAILIF(NULL == (queryPoint = (PPointT)MALLOC(sizeof(PointT))));
  FAILIF(NULL == (queryPoint->coordinates = (RealT*)MALLOC(pointsDimension * sizeof(RealT))));

  //读取查询点的文件
  FILE *queryFile = fopen(args[7], "rt");
  FAILIF(queryFile == NULL);
  TimeVarT meanQueryTime = 0;
  PPointAndRealTStructT *distToNN = NULL;
  for(IntT i = 0; i < nQueries; i++)
  {//对于每一个要查询的点

    RealT sqrLength = 0;
    // read in the query point.
    for(IntT d = 0; d < pointsDimension; d++)
	{

      FSCANF_REAL(queryFile, &(queryPoint->coordinates[d]));
      sqrLength += SQR(queryPoint->coordinates[d]);


	  /*//test
	  if (d >150 &&  d<160)
	  {
		  printf(" %lf ",queryPoint->coordinates[d]);
	  }
	  if ( d==160)
	  {
		  printf("原始的文件数据\n");
	  }
	  */
	  
    }
    queryPoint->sqrLength = sqrLength;
    //printRealVector("Query: ", pointsDimension, queryPoint->coordinates);


	
    // get the near neighbors.
    IntT nNNs = 0;
    for(IntT r = 0; r < nRadii; r++)
	{//查询n个近邻点,并计算距离

		//查询核心
      nNNs = getRNearNeighbors(nnStructs[r], queryPoint, result, resultSize);



      printf("Total time for R-NN query at radius %0.6lf (radius no. %d):\t%0.6lf\n", (double)(listOfRadii[r]), r, timeRNNQuery);
      meanQueryTime += timeRNNQuery;

      if (nNNs > 0)
	  {
		printf("Query point %d: found %d NNs at distance %0.6lf (%dth radius). First %d NNs are:\n", 
			i, nNNs, (double)(listOfRadii[r]), r, MIN(nNNs, MAX_REPORTED_POINTS));
	
		// compute the distances to the found NN, and sort according to the distance
		//计算近邻点和查询点的距离
		FAILIF(NULL == (distToNN = (PPointAndRealTStructT*)REALLOC(distToNN, nNNs * sizeof(*distToNN))));
		for(IntT p = 0; p < nNNs; p++)
		{
		  distToNN[p].ppoint = result[p];
		  distToNN[p].real = distance(pointsDimension, queryPoint, result[p]);
		}
		qsort(distToNN, nNNs, sizeof(*distToNN), comparePPointAndRealTStructT);

		// Print the points
		for(IntT j = 0; j < MIN(nNNs, MAX_REPORTED_POINTS); j++)
		{
		  ASSERT(distToNN[j].ppoint != NULL);
		  printf("%09d\tDistance:%0.6lf\n", distToNN[j].ppoint->index, distToNN[j].real);
		  CR_ASSERT(distToNN[j].real <= listOfRadii[r]);
		  //DPRINTF("Distance: %lf\n", distance(pointsDimension, queryPoint, result[j]));
		  //printRealVector("NN: ", pointsDimension, result[j]->coordinates);
		}
		break;
      }
    }
    if (nNNs == 0)
	{
      printf("Query point %d: no NNs found.\n", i);
    }
  }//  for(IntT i = 0; i < nQueries; i++)每个点查询

  //
  if (nQueries > 0)
  {
    meanQueryTime = meanQueryTime / nQueries;
    printf("Mean query time: %0.6lf\n", (double)meanQueryTime);
  }


  for(IntT i = 0; i < nRadii; i++)
  {
    freePRNearNeighborStruct(nnStructs[i]);
  }
  // XXX: should ideally free the other stuff as well.


  return 0;
}
Beispiel #30
0
QVariant getProperty(P_ID id, const QDomElement& e)
      {
      const QString& value(e.text());
      switch(propertyType(id)) {
            case T_BOOL:
                  return QVariant(bool(value.toInt()));
            case T_SUBTYPE:
            case T_INT:
                  return QVariant(value.toInt());
            case T_REAL:
            case T_SREAL:
                  return QVariant(value.toDouble());
            case T_FRACTION:
                  return QVariant::fromValue(readFraction(e));
            case T_COLOR:
                  return QVariant(readColor(e));
            case T_POINT:
                  return QVariant(readPoint(e));
            case T_SCALE:
            case T_SIZE:
                  return QVariant(readSize(e));
            case T_STRING:
                  return QVariant(value);
            case T_DIRECTION:
                  {
                  if (value == "up")
                        return QVariant(MScore::UP);
                  else if (value == "down")
                        return QVariant(MScore::DOWN);
                  else if (value == "auto")
                        return QVariant(MScore::AUTO);
                  }
                  break;
            case T_DIRECTION_H:
                  {
                  if (value == "left")
                        return QVariant(MScore::DH_LEFT);
                  else if (value == "right")
                        return QVariant(MScore::DH_RIGHT);
                  else if (value == "auto")
                        return QVariant(MScore::DH_AUTO);
                  }
                  break;
            case T_LAYOUT_BREAK:
                  if (value == "line")
                        return QVariant(int(LAYOUT_BREAK_LINE));
                  if (value == "page")
                        return QVariant(int(LAYOUT_BREAK_PAGE));
                  if (value == "section")
                        return QVariant(int(LAYOUT_BREAK_SECTION));
                  qDebug("getProperty: invalid T_LAYOUT_BREAK: <%s>", qPrintable(value));
                  break;
            case T_VALUE_TYPE:
                  if (value == "offset")
                        return QVariant(int(MScore::OFFSET_VAL));
                  else if (value == "user")
                        return QVariant(int(MScore::USER_VAL));
                  break;
            case T_BEAM_MODE:             // TODO
                  return QVariant(int(0));
            }
      return QVariant();
      }