コード例 #1
0
void EnrichmentDialog::setBestSize()
{
	TexWidget *tw = qobject_cast<TexWidget *>(d_widget);
	if (tw){
		tw->setBestSize();
		displayCoordinates(unitBox->currentIndex());
		d_plot->multiLayer()->notifyChanges();
	}
}
コード例 #2
0
ファイル: EnrichmentDialog.cpp プロジェクト: kuzavas/qtiplot
void EnrichmentDialog::setBestSize()
{
	ImageWidget *iw = qobject_cast<ImageWidget *>(d_widget);
	if (iw){
		iw->setSize(iw->pixmap().size());
		displayCoordinates(unitBox->currentIndex());
		d_plot->multiLayer()->notifyChanges();
		return;
	}

	TexWidget *tw = qobject_cast<TexWidget *>(d_widget);
	if (tw){
		tw->setBestSize();
		displayCoordinates(unitBox->currentIndex());
		d_plot->multiLayer()->notifyChanges();
		return;
	}
}
コード例 #3
0
ファイル: anaxUI.cpp プロジェクト: XIMrPantsIX/Comp441Project
void Anax::dialogChecker(){
	displayCoordinates();
	//switch(static_cast<int>(world_coordinates)){

	//case 400:
	//	turnDialogOn();
	//	dialogIn = "******";
	//	break;
	//case 2111:
	//	turnDialogOn();
	//	dialogIn = "******";
	//	break;
	//}
}
コード例 #4
0
ファイル: NavigationWidget.cpp プロジェクト: StephenCEI/2011
NavigationWidget::NavigationWidget(QWidget *parent) :
		QWidget(parent)
{
	setupUi(this);

        //navView = new NavigationView(this);
        //verticalLayout->insertWidget(0, navView);
	connect(navView, SIGNAL(mouseAtGeoPos(QPointF)), this, SLOT(displayCoordinates(QPointF)));

	triangulationWidget = new TriangulationWidget();
	connect(triangulationButton, SIGNAL(clicked()), triangulationWidget, SLOT(show()));
        connect(connectLineButton, SIGNAL(clicked()), navView, SLOT(plotLineForSelected()));
        connect(markIsectButton, SIGNAL(clicked()), navView, SLOT(plotLineIntersection()));

        connect(requestGPSButton, SIGNAL(clicked()), this, SLOT(sendGPSRequest()));

        connect(RobotController::gpsController(), SIGNAL(gotPositionUpdate(GPSPositionData)), this, SLOT(gotGPSUpdate(GPSPositionData)));

        connect(navView, SIGNAL(newPointAdded(QPointF)), triangulationSidebar, SLOT(addPoint(QPointF)));
        connect(navView, SIGNAL(newLineAdded(QPointF,QPointF)), triangulationSidebar, SLOT(addLine(QPointF,QPointF)));
        connect(navView, SIGNAL(newLandmarkAdded(QPointF)), triangulationSidebar, SLOT(addLandmark(QPointF)));

        connect(triangulationSidebar, SIGNAL(selectPoint(QPointF, bool)), navView, SLOT(selectPoint(QPointF, bool)));
        connect(triangulationSidebar, SIGNAL(clearSelectedPoints()), navView, SLOT(clearSelectedPoints()));

        connect(triangulationSidebar, SIGNAL(drawLine(QPointF,QPointF)), navView, SLOT(plotLineForPoints(QPointF,QPointF)));
        connect(triangulationSidebar, SIGNAL(selectLines(QList<QPair<QPointF,QPointF> >)), navView, SLOT(selectLines(QList<QPair<QPointF,QPointF> >)));
        connect(triangulationSidebar, SIGNAL(clearSelectedLines()), navView, SLOT(clearSelectedLines()));
        connect(triangulationSidebar, SIGNAL(intersectLines()), navView, SLOT(plotLineIntersection()));

        connect(triangulationSidebar, SIGNAL(deleteLines()), navView, SLOT(deleteSelectedLines()));
        connect(triangulationSidebar, SIGNAL(deletePoints()), navView, SLOT(deleteSelectedPoints()));
	
	// Test rover slots
        /*navView->setRoverPosition(QPointF(-110.791497, 38.406392));
	navView->setRoverPosition(QPointF(-110.790889, 38.406158));
	navView->setRoverPosition(QPointF(-110.790469, 38.405850));
	navView->setRoverPosition(QPointF(-110.790257, 38.405575));
	navView->setRoverPosition(QPointF(-110.790161, 38.405359));
	navView->setRoverPosition(QPointF(-110.790177, 38.405195));
	navView->setRoverPosition(QPointF(-110.790037, 38.404941));
        navView->setRoverPosition(QPointF(-110.789840, 38.404890));
	navView->setRoverPosition(QPointF(-110.789420, 38.404986));
	navView->setRoverPosition(QPointF(-110.789219, 38.404973));
        navView->setRoverHeading(92.334915);*/

        //navView->setRoverPosition(QPointF(-123.212968,44.674917)); // adair
        //navView->setRoverPosition(QPointF(-123.274951,44.567328)); // covell parking lot
}
コード例 #5
0
void LineDialog::initGeometryTab()
{
	unitBox = new QComboBox();
	unitBox->insertItem(tr("Scale Coordinates"));
	unitBox->insertItem(tr("Pixels"));

	QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
	bl1->addWidget(new QLabel(tr( "Unit" )));
	bl1->addWidget(unitBox);

    QGroupBox *gb1 = new QGroupBox(tr("Start Point"));
	xStartBox = new QLineEdit();
	yStartBox = new QLineEdit();

    QGridLayout *gl1 = new QGridLayout();
    gl1->addWidget(new QLabel( tr("X")), 0, 0);
    gl1->addWidget(xStartBox, 0, 1);
    gl1->addWidget(new QLabel(tr("To")), 1, 0);
    gl1->addWidget(yStartBox, 1, 1);
    gb1->setLayout(gl1);

    QGroupBox *gb2 = new QGroupBox(tr("End Point"));
    xEndBox = new QLineEdit();
	yEndBox = new QLineEdit();

    QGridLayout *gl2 = new QGridLayout();
    gl2->addWidget(new QLabel( tr("X")), 0, 0);
    gl2->addWidget(xEndBox, 0, 1);
    gl2->addWidget(new QLabel(tr("To")), 1, 0);
    gl2->addWidget(yEndBox, 1, 1);
    gb2->setLayout(gl2);

    QBoxLayout *bl2 = new QBoxLayout (QBoxLayout::LeftToRight);
	bl2->addWidget(gb1);
	bl2->addWidget(gb2);

	QVBoxLayout* vl = new QVBoxLayout();
    vl->addLayout(bl1);
    vl->addLayout(bl2);

    geometry = new QWidget();
    geometry->setLayout(vl);
	tw->addTab(geometry, tr( "&Geometry" ) );

	connect( unitBox, SIGNAL( activated(int) ), this, SLOT(displayCoordinates(int) ) );
	displayCoordinates(0);
}
コード例 #6
0
ファイル: EnrichmentDialog.cpp プロジェクト: kuzavas/qtiplot
void EnrichmentDialog::setWidget(QWidget *w)
{
	if (!w || !d_app)
		return;

	d_widget = w;

    FrameWidget *fw = qobject_cast<FrameWidget *>(d_widget);
    if (fw){
	#ifndef QT_MAC_USE_COCOA
		if (d_plot)
			d_plot->deselectMarker();
	#endif

		frameBox->blockSignals(true);
        frameBox->setCurrentIndex(fw->frameStyle());
		frameBox->blockSignals(false);

		frameColorBtn->blockSignals(true);
        frameColorBtn->setColor(fw->frameColor());
		frameColorBtn->blockSignals(false);

		boxFrameLineStyle->blockSignals(true);
		boxFrameLineStyle->setStyle(fw->framePen().style());
		boxFrameLineStyle->blockSignals(false);

		boxFrameWidth->blockSignals(true);
		if (d_widget_type == Ellipse)
			boxFrameWidth->setValue(fw->framePen().widthF());
		else
			boxFrameWidth->setValue(fw->framePen().width());
		boxFrameWidth->blockSignals(false);

		unitBox->setCurrentIndex(d_app->d_frame_geometry_unit);
		attachToBox->setCurrentIndex((int)fw->attachPolicy());
		displayCoordinates(d_app->d_frame_geometry_unit);
    } else {
		unitBox->setCurrentIndex(FrameWidget::Pixel);
		displayCoordinates(FrameWidget::Pixel);
	}

	if (d_widget_type == Text){
		LegendWidget *l = qobject_cast<LegendWidget *>(d_widget);
		if (l){
			setText(textEditBox, l->text());
			textFont = l->font();
			QFont fnt = textFont;
			fnt.setPointSize(QFont().pointSize() + 2);
			textEditBox->setFont(fnt);
			textColorBtn->blockSignals(true);
			textColorBtn->setColor(l->textColor());
			textColorBtn->blockSignals(false);

			QColor bc = l->backgroundColor();
			boxBackgroundTransparency->blockSignals(true);
			boxBackgroundTransparency->setValue(100*bc.alphaF());
			boxBackgroundTransparency->blockSignals(false);

			transparencySlider->blockSignals(true);
			transparencySlider->setValue(boxBackgroundTransparency->value());
			transparencySlider->blockSignals(false);

			textBackgroundBtn->blockSignals(true);
			textBackgroundBtn->setEnabled(bc.alpha());
			bc.setAlpha(255);
			textBackgroundBtn->setColor(bc);
			textBackgroundBtn->blockSignals(false);

			boxTextAngle->blockSignals(true);
            boxTextAngle->setValue(l->angle());
			boxTextAngle->blockSignals(false);
			autoUpdateTextBox->setChecked(l->isAutoUpdateEnabled());
			texOutputBox->setChecked(l->hasTeXOutput());
			updateButtons();
		}
	} else if (d_widget_type == Tex){
		TexWidget *tw = qobject_cast<TexWidget *>(d_widget);
		if (tw){
			setText(equationEditor, tw->formula());
			outputLabel->setPixmap(tw->pixmap());
			bestSizeButton->show();
		}
		return;
	} else if (d_widget_type == Image){
		ImageWidget *i = qobject_cast<ImageWidget *>(d_widget);
		if (i){
			imagePathBox->setText(i->fileName());
			boxSaveImagesInternally->blockSignals(true);
			boxSaveImagesInternally->setChecked(i->saveInternally());
			boxSaveImagesInternally->blockSignals(false);

			bestSizeButton->show();
		}
	} else if (d_widget_type == Frame || d_widget_type == Ellipse){
		QColor bc = fw->backgroundColor();

		boxTransparency->blockSignals(true);
		boxTransparency->setValue(100.0*bc.alphaF());
		boxTransparency->blockSignals(false);

		fillTransparencySlider->blockSignals(true);
		fillTransparencySlider->setValue(boxTransparency->value());
		fillTransparencySlider->blockSignals(false);

		bc.setAlpha(255);
		backgroundColorBtn->blockSignals(true);
		backgroundColorBtn->setColor(bc);
		backgroundColorBtn->blockSignals(false);

		patternBox->blockSignals(true);
		patternBox->setPattern(fw->brush().style());
		patternBox->blockSignals(false);

		patternColorBtn->blockSignals(true);
		patternColorBtn->setColor(fw->brush().color());
		patternColorBtn->blockSignals(false);
	}
}
コード例 #7
0
void EnrichmentDialog::setWidget(QWidget *w)
{
	if (!w)
		return;

	ApplicationWindow *app = (ApplicationWindow *)parent();
	if (!app)
		return;

	d_widget = w;

    FrameWidget *fw = qobject_cast<FrameWidget *>(d_widget);
    if (fw){
		frameBox->blockSignals(true);
        frameBox->setCurrentIndex(fw->frameStyle());
		frameBox->blockSignals(false);

		frameColorBtn->blockSignals(true);
        frameColorBtn->setColor(fw->frameColor());
		frameColorBtn->blockSignals(false);

		boxFrameLineStyle->blockSignals(true);
		boxFrameLineStyle->setStyle(fw->framePen().style());
		boxFrameLineStyle->blockSignals(false);

		boxFrameWidth->blockSignals(true);
		if (d_widget_type == Ellipse)
			boxFrameWidth->setValue(fw->framePen().widthF());
		else
			boxFrameWidth->setValue(fw->framePen().width());
		boxFrameWidth->blockSignals(false);

		unitBox->setCurrentIndex(app->d_frame_geometry_unit);
		attachToBox->setCurrentIndex((int)fw->attachPolicy());
		displayCoordinates(app->d_frame_geometry_unit);
    } else {
		unitBox->setCurrentIndex(FrameWidget::Pixel);
		displayCoordinates(FrameWidget::Pixel);
	}

	if (d_widget_type == Text){
		LegendWidget *l = qobject_cast<LegendWidget *>(d_widget);
		if (l){
			setText(textEditBox, l->text());
			textFont = l->font();
			QFont fnt = textFont;
			fnt.setPointSize(QFont().pointSize() + 2);
			textEditBox->setFont(fnt);
			textColorBtn->blockSignals(true);
			textColorBtn->setColor(l->textColor());
			textColorBtn->blockSignals(false);

			QColor bc = l->backgroundColor();
			boxBackgroundTransparency->blockSignals(true);
			boxBackgroundTransparency->setValue(bc.alpha());
			boxBackgroundTransparency->blockSignals(false);

			textBackgroundBtn->blockSignals(true);
			textBackgroundBtn->setEnabled(bc.alpha());
			textBackgroundBtn->setColor(bc);
			textBackgroundBtn->blockSignals(false);

			boxTextAngle->blockSignals(true);
            boxTextAngle->setValue(l->angle());
			boxTextAngle->blockSignals(false);
			autoUpdateTextBox->setChecked(l->isAutoUpdateEnabled());
			texOutputBox->setChecked(l->hasTeXOutput());
		}
	} else if (d_widget_type == Tex){
		TexWidget *tw = qobject_cast<TexWidget *>(d_widget);
		if (tw){
			setText(equationEditor, tw->formula());
			outputLabel->setPixmap(tw->pixmap());
			bestSizeButton->show();
		}
		return;
	} else if (d_widget_type == Image){
		ImageWidget *i = qobject_cast<ImageWidget *>(d_widget);
		if (i){
			imagePathBox->setText(i->fileName());
			boxSaveImagesInternally->blockSignals(true);
			boxSaveImagesInternally->setChecked(i->saveInternally());
			boxSaveImagesInternally->blockSignals(false);
		}
	} else if (d_widget_type == Frame){
		RectangleWidget *r = qobject_cast<RectangleWidget *>(d_widget);
		if (r){
			backgroundColorBtn->blockSignals(true);
			backgroundColorBtn->setColor(r->backgroundColor());
			backgroundColorBtn->blockSignals(false);

			boxTransparency->blockSignals(true);
			boxTransparency->setValue(r->backgroundColor().alpha());
			boxTransparency->blockSignals(false);

			patternBox->blockSignals(true);
			patternBox->setPattern(r->brush().style());
			patternBox->blockSignals(false);

			patternColorBtn->blockSignals(true);
			patternColorBtn->setColor(r->brush().color());
			patternColorBtn->blockSignals(false);
		}
	} else if (d_widget_type == Ellipse){
		EllipseWidget *r = qobject_cast<EllipseWidget *>(d_widget);
		if (r){
			backgroundColorBtn->blockSignals(true);
			backgroundColorBtn->setColor(r->backgroundColor());
			backgroundColorBtn->blockSignals(false);

			boxTransparency->blockSignals(true);
			boxTransparency->setValue(r->backgroundColor().alpha());
			boxTransparency->blockSignals(false);

			patternBox->blockSignals(true);
			patternBox->setPattern(r->brush().style());
			patternBox->blockSignals(false);

			patternColorBtn->blockSignals(true);
			patternColorBtn->setColor(r->brush().color());
			patternColorBtn->blockSignals(false);
		}
	}
}
コード例 #8
0
int QTweetStatusUpdateWithMedia::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTweetNetBase::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 2)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 2;
    } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
        if (_id < 2)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 2;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = status(); break;
        case 1: *reinterpret_cast< QString*>(_v) = imageFilename(); break;
        case 2: *reinterpret_cast< bool*>(_v) = isSensitive(); break;
        case 3: *reinterpret_cast< qint64*>(_v) = inReplyToStatusID(); break;
        case 4: *reinterpret_cast< double*>(_v) = latitude(); break;
        case 5: *reinterpret_cast< double*>(_v) = longitude(); break;
        case 6: *reinterpret_cast< QString*>(_v) = placeID(); break;
        case 7: *reinterpret_cast< bool*>(_v) = displayCoordinates(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setStatus(*reinterpret_cast< QString*>(_v)); break;
        case 1: setImageFilename(*reinterpret_cast< QString*>(_v)); break;
        case 2: setSensitive(*reinterpret_cast< bool*>(_v)); break;
        case 3: setReplyToStatusID(*reinterpret_cast< qint64*>(_v)); break;
        case 4: setLatitude(*reinterpret_cast< double*>(_v)); break;
        case 5: setLongitude(*reinterpret_cast< double*>(_v)); break;
        case 6: setPlaceID(*reinterpret_cast< QString*>(_v)); break;
        case 7: setDisplayCoordinates(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    } else if (_c == QMetaObject::RegisterPropertyMetaType) {
        if (_id < 8)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
コード例 #9
0
ファイル: LineDialog.cpp プロジェクト: trnielsen/mantid
void LineDialog::initGeometryTab()
{
	if (unitBox == NULL)
    unitBox = new QComboBox();
	unitBox->insertItem(tr("Scale Coordinates"));
	unitBox->insertItem(tr("Pixels"));

	QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
	bl1->addWidget(new QLabel(tr( "Unit" )));
	bl1->addWidget(unitBox);

	ApplicationWindow *app = dynamic_cast<ApplicationWindow *>(this->parent());
	QLocale locale = QLocale();
	if (app)
		locale = app->locale();
	
    QGroupBox *gb1 = new QGroupBox(tr("Start Point"));
	xStartBox = new DoubleSpinBox();
	xStartBox->setLocale(locale);
	xStartBox->setDecimals(6);
	yStartBox = new DoubleSpinBox();
	yStartBox->setLocale(locale);
	yStartBox->setDecimals(6);
	
	xStartPixelBox = new QSpinBox();
	xStartPixelBox->setRange(-INT_MAX, INT_MAX);
	yStartPixelBox = new QSpinBox();
	yStartPixelBox->setRange(-INT_MAX, INT_MAX);

    QGridLayout *gl1 = new QGridLayout();
    gl1->addWidget(new QLabel( tr("X")), 0, 0);
    gl1->addWidget(xStartBox, 0, 1);
	gl1->addWidget(xStartPixelBox, 0, 1);
    gl1->addWidget(new QLabel(tr("To")), 1, 0);
    gl1->addWidget(yStartBox, 1, 1);
	gl1->addWidget(yStartPixelBox, 1, 1);
	gl1->setColumnStretch(1, 10);
	gl1->setRowStretch(2, 1);
    gb1->setLayout(gl1);

    QGroupBox *gb2 = new QGroupBox(tr("End Point"));
    xEndBox = new DoubleSpinBox();
	xEndBox->setLocale(locale);
	xEndBox->setDecimals(6);
	yEndBox = new DoubleSpinBox();
	yEndBox->setLocale(locale);
	yEndBox->setDecimals(6);
	
	xEndPixelBox = new QSpinBox();
	xEndPixelBox->setRange(-INT_MAX, INT_MAX);
	yEndPixelBox = new QSpinBox();
	yEndPixelBox->setRange(-INT_MAX, INT_MAX);
	
    QGridLayout *gl2 = new QGridLayout();
    gl2->addWidget(new QLabel( tr("X")), 0, 0);
    gl2->addWidget(xEndBox, 0, 1);
	gl2->addWidget(xEndPixelBox, 0, 1);
	
    gl2->addWidget(new QLabel(tr("To")), 1, 0);
    gl2->addWidget(yEndBox, 1, 1);
	gl2->addWidget(yEndPixelBox, 1, 1);
	gl2->setColumnStretch(1, 10);
	gl2->setRowStretch(2, 1);
    gb2->setLayout(gl2);

    QBoxLayout *bl2 = new QBoxLayout (QBoxLayout::LeftToRight);
	bl2->addWidget(gb1);
	bl2->addWidget(gb2);

	QVBoxLayout* vl = new QVBoxLayout();
    vl->addLayout(bl1);
    vl->addLayout(bl2);

    geometry = new QWidget();
    geometry->setLayout(vl);
	tw->addTab(geometry, tr( "&Geometry" ) );

	connect(unitBox, SIGNAL(activated(int)), this, SLOT(displayCoordinates(int)));
	displayCoordinates(0);
}
コード例 #10
0
ファイル: mbmmethod.cpp プロジェクト: Dongyuyang/ann
int main(int argc, char** argv)
{
	uint32_t dim = 2;
	uint32_t n = 8;
	uint32_t N = 100;

	/*read static data set*/
	vector <Point> P;
	P = genPoints(dim, N, 1, 0);
//	displayPset(P);

	try {
		IStorageManager* memfile = StorageManager::createNewMemoryStorageManager();
		StorageManager::IBuffer* file = StorageManager::createNewRandomEvictionsBuffer(*memfile, 10, false);
		id_type indexIdentifier;
		ISpatialIndex* tree = RTree::createNewRTree(*file, 0.7, CAPACITY, CAPACITY, dim, SpatialIndex::RTree::RV_RSTAR, indexIdentifier);
		id_type id = 0;
		for(uint32_t i = 0; i < N; ++i)
		{
			std::ostringstream os;
			os << P[i];
			std::string data = os.str();
			tree->insertData(data.size() + 1, reinterpret_cast<const byte*>(data.c_str()), P[i], id);
			id++;
		}

	for(uint32_t loop = 1; loop <= LOOPNUM; ++loop)
	{
		cout << "/**************** BEGIN " << loop << " ***************/" << endl;

		/*generate query set*/
		vector <Point> Q;
		Q = genPoints(dim, n, 1, loop);
		/*double pdata1[] = {0, 0};
		double pdata2[] = {0, 1};
		double pdata3[] = {1, 1};
		Point q1(pdata1, dim), q2(pdata2, dim), q3(pdata3, dim);
		Q.push_back(q1);
		Q.push_back(q2);
		Q.push_back(q3);
		displayPset(Q);  */
		
		/*************** BEGIN BF MBM method ******************/
		/* MBM method for finding ANN of Q */
		CATCH mbmcost;
		mbmcost.catch_time();

		Region M = getMBR(Q, dim, n);
		MyQueryStrategy qs(M, Q, FUN);
		tree->queryStrategy(qs);

		mbmcost.catch_time();
		cout << "MBM: cpu cost is " << mbmcost.get_cost(2) << " millisecond(s)" << endl;
		cout << "MBM: best_dist is " << qs.best_dist << endl;
		cout << "MBM: best_NN is ";
		displayCoordinates(qs.best_NN);
		cout << "MBM: leafIO = " << qs.mbm_leafIO << "; indexIO = " << qs.mbm_indexIO << endl << endl;
		/*************** END BF MBM method *******************/
		
		cout << "/**************** END " << loop << " ****************/" << endl << endl;

	} // end loop
		
		delete tree;
		delete file;
		delete memfile;
	}
	catch(Tools::Exception& e)
	{
		cerr << "*********ERROR**********" << endl;
		std::string s = e.what();
		cerr << s << endl;
		return -1;
	}
	catch(...)
	{
		cerr << "**********ERROR********" << endl;
		return -1;
	}

	return 1;
}
コード例 #11
0
ファイル: main.cpp プロジェクト: Dongyuyang/ann
int main(int argc, char** argv)
{
	if (argc != 4)
	{
		cerr << "Usage: " << argv[0] << " dim n area." << endl;
		return -1;
	}

	int dim = atol(argv[1]);
	int n = atol(argv[2]);
	double area = atof(argv[3]);
	if(dim <= 0)
	{
		cerr << "Dimension should be larger than 0." << endl;
		return -1;
	}
	if(n <= 0)
	{
		cerr << "The number of query points should be larger than 0." << endl;
		return -1;
	}
	if(area <= 0 || area > 1)
	{
		cerr << "the area of query points should be in (0, 1]." << endl;
		return -1;
	}

	/*read static data set*/
	vector <Point> P;
	ifstream in("../data.ini");
	if(!in)
	{
		cerr << "Cannot open file data.ini.\n";
		return -1;
	}
 	P = readPoints(in, dim);
	uint32_t N = P.size();

	try {
		IStorageManager* memfile = StorageManager::createNewMemoryStorageManager();
		StorageManager::IBuffer* file = StorageManager::createNewRandomEvictionsBuffer(*memfile, 10, false);
		id_type indexIdentifier;
		ISpatialIndex* tree = RTree::createNewRTree(*file, 0.7, CAPACITY, CAPACITY, dim, SpatialIndex::RTree::RV_RSTAR, indexIdentifier);
		id_type id = 0;
		for(uint32_t i = 0; i < N; ++i)
		{
			std::ostringstream os;
			os << P[i];
			std::string data = os.str();
			tree->insertData(data.size() + 1, reinterpret_cast<const byte*>(data.c_str()), P[i], id);
			id++;
		}
		/*std::cerr << "Operations: " << N << std::endl;
		std::cerr << *tree;
		std::cerr << "Buffer hits: " << file->getHits() << std::endl;
		std::cerr << "Index ID: " << indexIdentifier << std::endl; 
		bool ret = tree->isIndexValid();
		if (ret == false) std::cerr << "ERROR: Structure is invalid!" << std::endl;
		else std::cerr << "The stucture seems O.K." << std::endl; */


	for(uint32_t loop = 1; loop <= LOOPNUM; ++loop)
	{
		cout << "/**************** BEGIN " << loop << " ***************/" << endl;

		/*generate query set*/
		vector <Point> Q;
		//Q = genPoints(dim, n, area, loop);
		stringstream ss;
		ss << "../query/n" << n << "M" << area << "/loop" << loop;
		cout << ss.str().c_str() << endl;
		ifstream qin(ss.str().c_str());
		if(!qin)
		{
			cerr << "Cannot open query file";
			return -1;
		}
		Q = readPoints(qin, dim);
		
		/*************** BEGIN MQM method ******************/
		MQM(tree, Q, n, FUN); // MQM method for finding ANN of Q
		/*************** END MQM method *******************/


		/*************** BEGIN ADM method ******************/
		CATCH cost1;
		cost1.catch_time();

		vector <uint32_t> nnIDs = nearestNeighborSet(tree, Q, n); // find the NN for every qi in Q as qi'
		vector <Point> newQ;
		for(uint32_t i = 0; i < n; ++i)
		{
			newQ.push_back(P[nnIDs[i]]);
		}
		cost1.catch_time();
		cout << "proposal method: cpu cost for finding NNs of Q as Q' is " << cost1.get_cost(2) << " millisecond(s)" << endl;

		/***** read dist-matrix index for Q' ********/
		uint32_t maxK = P.size() / RATIO; // the length of dist-matrix index
		uint32_t * dmindex[n];
		for(uint32_t i = 0; i < n; ++i)
	 	{ // read the dist-matrix index of qi'
			dmindex[i] = readDMIndex(nnIDs[i], maxK);
			if (dmindex[i] == NULL)
			{
				cerr << "error for loading Dist-Matrix Index." << endl;
				return -1;
			}
		}

		double minadist  = 0;
		/* ADM method for finding approxiamte ANN  */
		Point adm_ANN = ADM(newQ, n, P, N, dmindex, maxK, FUN, minadist, ERROR_RATE);
		cout << "ADM: best_dist is " << getAdist(adm_ANN, Q, n, FUN) << endl << endl; 
		/*************** END ADM method *******************/

		/*************** BEGIN approxiamte vp-ANN method ******************/
		/* approximate vp-ANN method for finding ANN of Q'*/
		CATCH cost2;
		cost2.catch_time();

		Point centroid = findCentroid(Q, dim, n);
		minadist = getAdist(centroid, Q, n, FUN);
		uint32_t vpID = nearestNeighbor(tree, centroid);
		uint32_t best_id_Q = epsilonANN(Q, n, P, N, vpID, dmindex, maxK, FUN); 

		cost2.catch_time();
		cout << "approxiamte vp-ANN method: cpu cost is " << cost2.get_cost(2) << " millisecond(s)" << endl;
		cout << "approximate vp-ANN method: best_dist is " << getAdist(P[best_id_Q], Q, n, FUN) << endl;
		cout << "approxiamte vp-ANN method: best_NN is ";
		displayCoordinates(P[best_id_Q]); 
		cout << endl;
		/*************** END approxiamte vp-ANN method *******************/


		/*************** BEGIN BF MBM method ******************/
		/* MBM method for finding ANN of Q */
		CATCH mbmcost;
		mbmcost.catch_time();

		Region M = getMBR(Q, dim, n);
		MyQueryStrategy qs = MyQueryStrategy(M, Q, FUN);
		tree->queryStrategy(qs);

		mbmcost.catch_time();
		cout << "MBM: cpu cost is " << mbmcost.get_cost(2) << " millisecond(s)" << endl;
		cout << "MBM: best_dist is " << qs.best_dist << endl;
		cout << "MBM: best_NN is ";
		displayCoordinates(qs.best_NN);
		cout << "MBM: leafIO = " << qs.mbm_leafIO << "; indexIO = " << qs.mbm_indexIO << endl << endl;
		/*************** END BF MBM method *******************/


		/*************** BEGIN brute method ******************/
		/* brute method for finding ANN of Q*/
		CATCH brute_cost;
		brute_cost.catch_time();

		uint32_t ANNid = brute_ANN(Q, n, P, N, FUN);

		brute_cost.catch_time();
		cout << "brute method: cpu cost is " << brute_cost.get_cost(2) << " millisecond(s)" << endl;
		double adist = getAdist(P[ANNid], Q, n, FUN);
		cout << "brute method: best_dist is " << adist << endl;
		cout << "brute method: best_NN is ";
		displayCoordinates(P[ANNid]);
		/*************** END brute method *******************/
		
		cout << "/**************** END " << loop << " ****************/" << endl << endl;

	} // end loop
		
		delete tree;
		delete file;
		delete memfile;
	}
	catch(Tools::Exception& e)
	{
		cerr << "*********ERROR**********" << endl;
		std::string s = e.what();
		cerr << s << endl;
		return -1;
	}
	catch(...)
	{
		cerr << "**********ERROR********" << endl;
		return -1;
	}

	return 1;
}