TEST_F(CoordinateTransformableDataObject_test, TransformAppliedToVisibleBounds) { const auto coordsSpec = ReferencedCoordinateSystemSpecification( CoordinateSystemType::geographic, "testSystem", {}, {}, {}, {}); const auto targetCoordsSpec = ReferencedCoordinateSystemSpecification( CoordinateSystemType::geographic, "otherTestSystem", {}, {}, {}, {}); auto data = genPolyData<TransformedPolyData>(); data->specifyCoordinateSystem(coordsSpec); auto transform = vtkSmartPointer<vtkTransform>::New(); transform->Translate(3, 4, 5); data->setTransform(transform); const auto dataSetBounds = DataBounds(data->dataSet()->GetBounds()); const auto dataBounds = data->bounds(); const auto shiftedBounds = data->bounds().shifted(vtkVector3d(3, 4, 5)); auto rendered = data->createRendered(); rendered->setDefaultCoordinateSystem(targetCoordsSpec); const auto visibleBounds = rendered->visibleBounds(); ASSERT_EQ(dataSetBounds, dataBounds); ASSERT_EQ(shiftedBounds, visibleBounds); }
TEST_P(MatricesToVtk_Grid3D_ptest, loadGrid3D) { const auto & param = GetParam(); io::ReadDataSet readDataSet; readDataSet.type = io::DataSetType::vectorGrid3D; auto & data = readDataSet.data; data = generateGrid(param); auto dataObject = MatricesToVtk::loadGrid3D("AGrid", { readDataSet }); ASSERT_TRUE(dataObject); auto image = vtkImageData::SafeDownCast(dataObject->dataSet()); ASSERT_TRUE(image); std::array<int, 3> dimensions; image->GetDimensions(dimensions.data()); ASSERT_EQ(2, dimensions[0]); ASSERT_EQ(2, dimensions[1]); ASSERT_EQ(2, dimensions[2]); tDataBounds expectedBounds; expectedBounds.setDimension(static_cast<size_t>(param._0), ValueRange<>({0.0, 1.0})); expectedBounds.setDimension(static_cast<size_t>(param._1), ValueRange<>({0.0, 2.0})); expectedBounds.setDimension(static_cast<size_t>(param._2), ValueRange<>({0.0, 3.0})); tDataBounds bounds; image->GetBounds(bounds.data()); ASSERT_EQ(expectedBounds, bounds); }
// This should be called on an interrupt timer whose period // is at most 1/(60*4) seconds (the number of rows times // POV time) void leddriver::tickLEDs() { int x = 0; // For looping // Turn of LEDS by setting current row to high impedance (aka input mode) highZRows(); // Increment row being displayed curLEDrow++; if (curLEDrow >= 4) curLEDrow = 0; // Push data out shift register // Hopefully gcc unrolls this for loop for(x = 0; x < 8; x++) { // Zero out data bit dataLow(); // Add 8 to register if led is active (mod 2 to convert nonzero to 1) dataSet(ledMatrix[curLEDrow] & (1 << x)); // Latch Data In latchHigh(); rlatchLow(); latchLow(); rlatchHigh(); } // Reenable output on new row by outputing a 'sink' on the current row sinkRow(curLEDrow); }
TEST_F(CoordinateTransformableDataObject_test, NullTransformKeepsBounds) { auto data = genPolyData<TransformedPolyData>(); const auto dataSetBounds = DataBounds(data->dataSet()->GetBounds()); const auto dataBounds = data->bounds(); const auto visibleBounds = data->createRendered()->visibleBounds(); ASSERT_EQ(dataSetBounds, dataBounds); ASSERT_EQ(dataBounds, visibleBounds); }
TEST_F(MatricesToVtk_Grid3D_test, read_points_from_vtkImageData) { auto image = vtkSmartPointer<vtkImageData>::New(); image->SetExtent(0, 2, 0, 3, 0, 2); image->SetSpacing(0.1, 0.1, 0.1); image->SetOrigin(-1.0, -2.0, -3.0); io::ReadDataSet readDataSet; readDataSet.type = io::DataSetType::vectorGrid3D; auto & data = readDataSet.data; const vtkIdType numPoints = image->GetNumberOfPoints(); // xyz (tested) + 3-component vector (not tested here) data.resize(6, std::vector<io::t_FP>(static_cast<size_t>(numPoints))); for (vtkIdType i = 0; i < numPoints; ++i) { const auto stdI = static_cast<size_t>(i); vtkVector3d point; image->GetPoint(i, point.GetData()); data[0u][stdI] = point.GetX(); data[1u][stdI] = point.GetY(); data[2u][stdI] = point.GetZ(); } auto parsedImage = MatricesToVtk::loadGrid3D("TestingGrid3D", { readDataSet }); ASSERT_TRUE(parsedImage); ASSERT_TRUE(parsedImage->dataSet()); ASSERT_EQ(numPoints, parsedImage->dataSet()->GetNumberOfPoints()); for (vtkIdType i = 0; i < numPoints; ++i) { vtkVector3d pRef, pParsed; image->GetPoint(i, pRef.GetData()); parsedImage->dataSet()->GetPoint(i, pParsed.GetData()); ASSERT_DOUBLE_EQ(pRef.GetX(), pRef.GetX()); ASSERT_DOUBLE_EQ(pRef.GetY(), pRef.GetY()); ASSERT_DOUBLE_EQ(pRef.GetZ(), pRef.GetZ()); } }
void DBConverter::addDropsDataToLearningSet(CardsSet dealerWithWidow, BidType contract, const vector< vector<Card> >& bestDrops, LearningData* learningData) { PrefAssert( bestDrops.size() > 0 ); // Determining drop index. int index = 0; int count = 17; // Infinity // From all drops leading to the same result select one with least cards count for( int i = 0; i < bestDrops.size(); i++ ) { RanksSet ranksSet1 = GetCardsOfSuit(dealerWithWidow, GetCardSuit(bestDrops[i][0])); RanksSet ranksSet2 = GetCardsOfSuit(dealerWithWidow, GetCardSuit(bestDrops[i][1])); if( RanksSetSize(ranksSet1) > RanksSetSize(ranksSet2) ) { continue; } int tmp = RanksSetSize(ranksSet1) + RanksSetSize(ranksSet2); if( GetCardSuit(bestDrops[i][0]) == GetCardSuit(bestDrops[i][1]) ) { tmp--; } if( tmp < count ) { count = tmp; index = i; } } const vector<Card>& drop = bestDrops[index]; CardsSet utilized = EmptyCardsSet; CardsSet playerCards = dealerWithWidow; GetLog() << drop[0] << " " << drop[1] << endl; for( int i = 0; i < drop.size(); i++ ) { vector<int> dataSet(1); dataSet[0] = -1; for( SuitForwardIterator itSuit; itSuit.HasNext(); itSuit.Next() ) { RanksSet ranksSet = GetCardsOfSuit(playerCards, itSuit.GetObject()); if( ranksSet == EmptyRanksSet ) { continue; } int value = GetRanksSetIndex(ranksSet, GetCardsOfSuit(utilized, itSuit.GetObject())); dataSet.push_back(value); if( itSuit.GetObject() == GetCardSuit(drop[i]) ) { dataSet[0] = dataSet.back(); } } assert( dataSet[0] >= 0 ); learningData->AddSet(dataSet); utilized = AddCardToSet(utilized, drop[i]); playerCards = RemoveCardFromSet(playerCards, drop[i]); } GetLog() << "Learning data was added" << endl; data->AddLayout(contract, RemoveCardFromSet(RemoveCardFromSet(dealerWithWidow, drop[0]), drop[1])); }
void EvaluationTestCase::ce() { const int N = 2; const int F = 2; Eigen::MatrixXd Y(N, F); Eigen::MatrixXd T(N, F); Y.row(0) << 0.5, 0.5; Y.row(1) << 0.0, 1.0; T.row(0) << 0.0, 1.0; T.row(1) << 1.0, 0.0; ReturnInput learner; OpenANN::DirectStorageDataSet dataSet(&Y, &T); double ce = OpenANN::ce(learner, dataSet); ASSERT_EQUALS_DELTA(ce, 23.72, 0.01); }
void EvaluationTestCase::rmse() { OpenANN::RandomNumberGenerator rng; const int N = 100000; const int F = 10; Eigen::MatrixXd Y(N, F); for(int n = 0; n < N; n++) for(int f = 0; f < F; f++) Y(n, f) = rng.sampleNormalDistribution<double>() * 2.0; Eigen::MatrixXd T(N, F); T.setZero(); ReturnInput learner; OpenANN::DirectStorageDataSet dataSet(&Y, &T); double rmse = OpenANN::rmse(learner, dataSet); ASSERT_EQUALS_DELTA(rmse, std::sqrt(F * 2.0 * 2.0), 0.5); }
void TestDataSetDAO::testCRUDDataSet() { // get the transactor std::auto_ptr<te::da::DataSourceTransactor> transactor = terrama2::core::ApplicationController::getInstance().getTransactor(); // create a new data provider and save it t the database terrama2::core::DataProviderPtr dataProvider(new terrama2::core::DataProvider("Server 1", terrama2::core::DataProvider::FTP_TYPE)); terrama2::core::DataProviderDAO::save(dataProvider, *transactor); // create a new dataset and save it to the database terrama2::core::DataSetPtr dataSet(new terrama2::core::DataSet(dataProvider, "Queimadas", terrama2::core::DataSet::OCCURENCE_TYPE)); te::dt::TimeDuration dataFrequency(2,0,0); dataSet->setDataFrequency(dataFrequency); terrama2::core::DataSetDAO::save(dataSet, *transactor); // assure we have a valid dataset identifier QVERIFY2(dataSet->id() > 0, "Id must be different than zero after save()!"); te::dt::TimeDuration schedule(12,0,0); dataSet->setSchedule(schedule); te::dt::TimeDuration scheduleTimeout(0,30,0); dataSet->setScheduleTimeout(scheduleTimeout); te::dt::TimeDuration scheduleRetry(0,5,0); dataSet->setScheduleRetry(scheduleRetry); dataSet->setStatus(terrama2::core::DataSet::ACTIVE); dataSet->setDescription("Description..."); dataSet->setName("New queimadas"); terrama2::core::DataSetDAO::update(dataSet, *transactor); terrama2::core::DataSetPtr findDataSet = terrama2::core::DataSetDAO::find(dataSet->id(), *transactor); QVERIFY2(dataSet->name() == findDataSet->name(), "Name must be the same!"); QVERIFY2(dataSet->status() == findDataSet->status(), "Status must be the same!"); QVERIFY2(dataSet->scheduleTimeout() == findDataSet->scheduleTimeout(), "Schedule timeout must be the same!"); QVERIFY2(dataSet->schedule() == findDataSet->schedule(), "Schedule must be the same!"); QVERIFY2(dataSet->scheduleRetry() == findDataSet->scheduleRetry(), "Schedule retry must be the same!"); QVERIFY2(dataSet->dataFrequency() == findDataSet->dataFrequency(), "Data frequency must be the same!"); }
TEST_P(MatricesToVtk_Grid3D_ptest, loadGrid3D_vector3) { const auto & param = GetParam(); io::ReadDataSet readDataSet; readDataSet.type = io::DataSetType::vectorGrid3D; auto & data = readDataSet.data; data = generateGrid(param, 3u); auto dataObject = MatricesToVtk::loadGrid3D("AGrid", { readDataSet }); ASSERT_TRUE(dataObject); auto image = vtkImageData::SafeDownCast(dataObject->dataSet()); ASSERT_TRUE(image); std::array<int, 3> dimensions; image->GetDimensions(dimensions.data()); ASSERT_EQ(2, dimensions[0]); ASSERT_EQ(2, dimensions[1]); ASSERT_EQ(2, dimensions[2]); auto vectors = image->GetPointData()->GetVectors(); ASSERT_TRUE(vectors); std::array<int, 3> refIncrements; refIncrements[static_cast<size_t>(param._0)] = 1; refIncrements[static_cast<size_t>(param._1)] = dimensions[0]; refIncrements[static_cast<size_t>(param._2)] = dimensions[0] * dimensions[1]; for (int z = 0; z < dimensions[2]; ++z) { for (int y = 0; y < dimensions[1]; ++y) { for (int x = 0; x < dimensions[0]; ++x) { const size_t refIndex = static_cast<size_t>( refIncrements[0] * x + refIncrements[1] * y + refIncrements[2] * z); for (int c = 0; c < 3; ++c) { const auto expected = static_cast<float>( data[3u + static_cast<size_t>(c)][refIndex]); const auto parsedComponent = image->GetScalarComponentAsFloat(x, y, z, c); ASSERT_FLOAT_EQ(expected, parsedComponent); } } } } }
void Communication::update(){ if(mutex == true) return; //mutex WOOT cout<<"in update"<<endl; mutex = true; readData(); int fudgeFix = 0; while(!q.empty()){ switch (q.front()){ case 'a': dataSet(0); break; case 'b': dataSet(1); break; case 'c': dataSet(2); break; case 'd': dataSet(3); break; case 'e': dataSet(4); break; case 'f': dataSet(5); break; case 'g': getAngle(1,1); break; case 'h': getAngle(1,2); break; case 'i': getAngle(1,3); break; case 'j': getAngle(2,1); break; case 'k': getAngle(2,2); break; case 'l': getAngle(2,3); break; default: q.pop(); cout<<"Something went wrong..."<<endl; break; } fudgeFix++; if (fudgeFix > 20){ int qsz = q.size(); for(int i = 0; i < qsz; i++) q.pop(); mutex = false; break; } } mutex = false; cout<<"out update"<<endl; }
void EvaluationTestCase::accuracy() { const int N = 3; const int F = 3; Eigen::MatrixXd Y(N, F); Eigen::MatrixXd T(N, F); Y.row(0) << 1.0, 0.0, 0.0; Y.row(1) << 0.0, 0.0, 1.0; Y.row(2) << 0.0, 1.0, 0.0; T.row(0) << 1.0, 0.0, 0.0; T.row(1) << 0.0, 1.0, 0.0; T.row(2) << 0.0, 1.0, 0.0; ReturnInput learner; OpenANN::DirectStorageDataSet dataSet(&Y, &T); double accuracy = OpenANN::accuracy(learner, dataSet); ASSERT_EQUALS_DELTA(accuracy, 0.667, 0.001); }
void MainWindow::openDataSet() { QString filename = QFileDialog::getOpenFileName(this, "Open Data Set", "", "Simulation files (*.nc)"); if(!filename.isEmpty()) { boost::shared_ptr<EpidemicDataSet> dataSet(new EpidemicDataSet(filename.toStdString().c_str())); if(dataSet->isValid() != true) { QMessageBox::warning(this, "Error", "Could not load data set.", QMessageBox::Ok, QMessageBox::Ok); } else { dataSet_ = dataSet; emit(dataSetChanged(dataSet_)); } } }
int main() { //srand((int)time(0)); LKDTreeMatrix dataSet(10, 3, 0.0f); LKDTreeMatrix data(1, 3); data[0][0] = 3.0f; data[0][1] = 2.5f; data[0][2] = -5.0f; LKDTree tree; for (unsigned int i = 0; i < 500; i++) { printf("Test Index: %u\n", i); RandMatrix(dataSet, -10.0f, 10.0f); if (i == 739) { printf("Stop\n"); } tree.BuildTree(dataSet); int predictNN = tree.SearchNearestNeighbor(data); int actualNN = FindNearestNeighbor(dataSet, data); if (actualNN != predictNN) { printf("Fail\n"); break; } } system("pause"); return 0; }
void EvaluationTestCase::confusionMatrix() { const int N = 5; const int F = 3; Eigen::MatrixXd Y(N, F); Eigen::MatrixXd T(N, F); Y.row(0) << 1.0, 0.0, 0.0; Y.row(1) << 1.0, 0.0, 0.0; Y.row(2) << 0.0, 1.0, 0.0; Y.row(3) << 0.0, 0.0, 1.0; Y.row(4) << 1.0, 0.0, 0.0; T.row(0) << 1.0, 0.0, 0.0; T.row(1) << 1.0, 0.0, 0.0; T.row(2) << 1.0, 0.0, 0.0; T.row(3) << 0.0, 0.0, 1.0; T.row(4) << 0.0, 0.0, 1.0; ReturnInput learner; OpenANN::DirectStorageDataSet dataSet(&Y, &T); Eigen::MatrixXi confusionMatrix = OpenANN::confusionMatrix(learner, dataSet); ASSERT_EQUALS(confusionMatrix(0, 0), 2); ASSERT_EQUALS(confusionMatrix(0, 1), 1); ASSERT_EQUALS(confusionMatrix(2, 0), 1); ASSERT_EQUALS(confusionMatrix(2, 2), 1); }
void DataObject::CopyStructure(vtkDataSet & other) { auto ds = dataSet(); if (!ds) { return; } // vtkPolyData applies a static_cast<vtkPolyData *>() to its argument if (!other.IsA(ds->GetClassName())) { qFatal(R"(Invalid call to DataObject::CopyStructure on "%s" with parameter of type "%s")", name().toUtf8().data(), other.GetClassName()); } const SetResetFlag setResetFlag(d_ptr->m_inCopyStructure); ds->CopyStructure(&other); // explicitly trigger Modified to catch up missed changes ds->Modified(); } vtkAlgorithmOutput * DataObject::processedOutputPort() { return d_ptr->pipelineEndPoint()->GetOutputPort(); } vtkDataSet * DataObject::processedOutputDataSet() { auto producer = d_ptr->pipelineEndPoint(); if (!producer->GetExecutive()->Update()) { return nullptr; } return vtkDataSet::SafeDownCast(producer->GetOutputDataObject(0)); } std::pair<bool, unsigned int> DataObject::injectPostProcessingStep(const PostProcessingStep & postProcessingStep) { return d_ptr->injectPostProcessingStep(postProcessingStep); } bool DataObject::erasePostProcessingStep(unsigned int id) { return d_ptr->erasePostProcessingStep(id); } const DataBounds & DataObject::bounds() const { return d_ptr->m_bounds; } vtkIdType DataObject::numberOfPoints() const { return d_ptr->m_numberOfPoints; } vtkIdType DataObject::numberOfCells() const { return d_ptr->m_numberOfCells; } QVtkTableModel * DataObject::tableModel() { if (!d_ptr->m_tableModel) { d_ptr->m_tableModel = createTableModel(); } return d_ptr->m_tableModel.get(); } void DataObject::addDataArray(vtkDataArray & /*dataArray*/) { } void DataObject::clearAttributes() { const std::array<QStringList, 3> intrinsicAttributes = [this] () { std::array<QStringList, 3> attrNames; // field, point, cell addIntrinsicAttributes(attrNames[0], attrNames[1], attrNames[2]); attrNames[0].prepend(nameAttributeName()); return attrNames; }(); if (!dataSet()) { return; } auto & ds = *dataSet(); const auto cleanupAttributes = [] (vtkFieldData & fd, const QStringList & intrinsicAttributes) { int i = 0; while (i < fd.GetNumberOfArrays()) { auto array = fd.GetAbstractArray(i); if (intrinsicAttributes.contains(QString::fromUtf8(array->GetName()))) { ++i; continue; } fd.RemoveArray(i); } }; cleanupAttributes(*ds.GetFieldData(), intrinsicAttributes[0]); cleanupAttributes(*ds.GetPointData(), intrinsicAttributes[1]); cleanupAttributes(*ds.GetCellData(), intrinsicAttributes[2]); } void DataObject::deferEvents() { d_ptr->lockEventDeferrals().deferEvents(); } void DataObject::executeDeferredEvents() { d_ptr->lockEventDeferrals().executeDeferredEvents(); } bool DataObject::isDeferringEvents() const { return d_ptr->lockEventDeferrals().isDeferringEvents(); } ScopedEventDeferral DataObject::scopedEventDeferral() { return ScopedEventDeferral(*this); } DataObject * DataObject::readPointer(vtkInformation & information) { static_assert(sizeof(int*) == sizeof(DataObject*), ""); if (information.Has(DataObjectPrivate::DATA_OBJECT())) { assert(information.Length(DataObjectPrivate::DATA_OBJECT()) == 1); return reinterpret_cast<DataObject *>(information.Get(DataObjectPrivate::DATA_OBJECT())); } return nullptr; } void DataObject::storePointer(vtkInformation & information, DataObject * dataObject) { information.Set(DataObjectPrivate::DATA_OBJECT(), reinterpret_cast<int *>(dataObject), 1); } QString DataObject::readName(vtkInformation & information) { if (!information.Has(DataObjectPrivate::DATA_OBJECT_NAME())) { return{}; } return QString::fromUtf8(information.Get(DataObjectPrivate::DATA_OBJECT_NAME())); } void DataObject::storeName(vtkInformation & information, const DataObject & dataObject) { information.Set(DataObjectPrivate::DATA_OBJECT_NAME(), dataObject.name().toUtf8().data()); } DataObjectPrivate & DataObject::dPtr() { return *d_ptr; } vtkAlgorithmOutput * DataObject::processedOutputPortInternal() { return d_ptr->trivialProducer()->GetOutputPort(); } void DataObject::addIntrinsicAttributes( QStringList & /*fieldAttributes*/, QStringList & /*pointAttributes*/, QStringList & /*cellAttributes*/) { } bool DataObject::checkIfBoundsChanged() { if (!dataSet()) { return false; } decltype(d_ptr->m_bounds) newBounds; dataSet()->GetBounds(newBounds.data()); bool changed = newBounds != d_ptr->m_bounds; if (changed) { d_ptr->m_bounds = newBounds; } return changed; } bool DataObject::checkIfValueRangeChanged() { // this depends on the actual kind of values return true; } bool DataObject::checkIfStructureChanged() { if (!dataSet()) { return false; } const vtkIdType newNumPoints = dataSet()->GetNumberOfPoints(); const vtkIdType newNumCells = dataSet()->GetNumberOfCells(); const bool changed = (newNumPoints != d_ptr->m_numberOfPoints) || (newNumCells != d_ptr->m_numberOfCells); d_ptr->m_numberOfPoints = newNumPoints; d_ptr->m_numberOfCells = newNumCells; return changed; } void DataObject::dataChangedEvent() { } void DataObject::boundsChangedEvent() { } void DataObject::valueRangeChangedEvent() { } void DataObject::structureChangedEvent() { } void DataObject::disconnectEventGroup(const QString & eventName) { d_ptr->disconnectEventGroup(eventName); } void DataObject::disconnectAllEvents() { d_ptr->disconnectAllEvents(); } void DataObject::signal_dataChanged() { auto lock = d_ptr->lockEventDeferrals(); if (lock.isDeferringEvents()) { lock.addDeferredEvent("dataChanged", std::bind(&DataObject::signal_dataChanged, this)); return; }
const vtkImageData & ImageDataObject::imageData() const { auto img = dataSet(); assert(dynamic_cast<const vtkImageData *>(img)); return static_cast<const vtkImageData &>(*img); }
int main(int argc, char ** argv) { QString volcR10("C:/develop/$sync/GFZ/data/VTK XML data/Volcano 2 topo.vtp"); auto object = Loader::readFile( volcR10 ); double bounds[6]; auto & dataSet = *object->dataSet(); dataSet.GetBounds(bounds); vtkVector2d A{ bounds[0], 0 }; vtkVector2d B{ bounds[1], 0 }; auto inputPolyData = dynamic_cast<PolyDataObject *>(object.get()); auto selector = vtkSmartPointer<LineOnCellsSelector2D>::New(); selector->SetInputData(&dataSet); selector->SetCellCentersConnection(inputPolyData->cellCentersOutputPort()); selector->SetStartPoint(A); selector->SetEndPoint(B); //auto extractSelection = vtkSmartPointer<vtkExtractSelectedPolyDataIds>::New(); //extractSelection->SetInputData(&dataSet); //extractSelection->SetInputConnection(1, selector->GetOutputPort()); //extractSelection->Update(); //auto vPoly = extractSelection->GetOutput(); //auto extractSelection = vtkSmartPointer<vtkExtractSelection>::New(); //extractSelection->SetInputData(&dataSet); //extractSelection->SetSelectionConnection(selector->GetOutputPort()); //extractSelection->Update(); //auto outputData = vtkUnstructuredGrid::SafeDownCast(extractSelection->GetOutput()); //auto vPoly = vtkSmartPointer<vtkPolyData>::New(); //vPoly->SetPoints(outputData->GetPoints()); //vPoly->SetPolys(outputData->GetCells()); //vPoly->GetCellData()->PassData(outputData->GetCellData()); //vPoly->GetPointData()->PassData(outputData->GetPointData()); selector->Update(); auto vPoly = selector->GetExtractedPoints(); auto poly = std::make_unique<PolyDataObject>("extraction", *vPoly); QApplication app(argc, argv); ColorMappingChooser cmc; cmc.show(); RenderConfigWidget rcw; rcw.show(); RendererConfigWidget rrcw; rrcw.show(); DataSetHandler dsh; DataMapping dm(dsh); auto view = dm.openInRenderView({ poly.get(), object.get() }); auto pointsVis = dynamic_cast<RenderedPolyData *>(view->visualizationFor(poly.get())); pointsVis->mainActor()->GetProperty()->SetPointSize(5); pointsVis->mainActor()->PickableOn(); auto baseVis = dynamic_cast<RenderedPolyData *>(view->visualizationFor(object.get())); baseVis->mainActor()->GetProperty()->SetOpacity(0.2); baseVis->mainActor()->PickableOff(); view->show(); cmc.setCurrentRenderView(view); rcw.setCurrentRenderView(view); rcw.setSelectedData(poly.get()); rrcw.setCurrentRenderView(view); return app.exec(); }
void CvReplayInfo::createInfo() { CvGame& game = GC.getGame(); const PlayerTypes eActivePlayer = game.getActivePlayer(); m_strMapScriptName = CvPreGame::mapScriptName(); m_eWorldSize = CvPreGame::worldSize(); m_eClimate = CvPreGame::climate(); m_eSeaLevel = CvPreGame::seaLevel(); m_eEra = CvPreGame::era(); m_eGameSpeed = game.getGameSpeedType(); m_listGameOptions.clear(); for(int i = 0; i < NUM_GAMEOPTION_TYPES; i++) { GameOptionTypes eOption = (GameOptionTypes)i; if(game.isOption(eOption)) { m_listGameOptions.push_back(eOption); } } m_listVictoryTypes.clear(); for(int i = 0; i < GC.getNumVictoryInfos(); i++) { VictoryTypes eVictory = (VictoryTypes)i; if(game.isVictoryValid(eVictory)) { m_listVictoryTypes.push_back(eVictory); } } m_eVictoryType = NO_VICTORY; m_iNormalizedScore = 0; if(NO_PLAYER != eActivePlayer) { CvPlayer& player = GET_PLAYER(eActivePlayer); if(game.getWinner() == player.getTeam()) { m_eVictoryType = game.getVictory(); } m_iNormalizedScore = player.GetScore(true, player.getTeam() == game.getWinner()); } //m_eGameType = CvPreGame::getGameType(); m_iInitialTurn = game.getStartTurn(); m_iStartYear = game.getStartYear(); m_iFinalTurn = game.getGameTurn(); CvGameTextMgr::setYearStr(m_strFinalDate, m_iFinalTurn, false, game.getCalendar(), game.getStartYear(), game.getGameSpeedType()); m_eCalendar = game.getCalendar(); m_dataSetMap.clear(); m_listPlayerDataSets.clear(); m_listPlayerInfo.clear(); m_listPlots.clear(); std::map<int, int> mapPlayers; mapPlayers[-1] = -1; //account for NO_PLAYER. m_iActivePlayer = -1; int iPlayerIndex = 0; for(int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; iPlayer++) { CvPlayer& player = GET_PLAYER((PlayerTypes)iPlayer); if(player.isEverAlive()) { //Ensure that final turn is stored. player.GatherPerTurnReplayStats(m_iFinalTurn); mapPlayers[iPlayer] = iPlayerIndex; if(iPlayer == game.getActivePlayer()) { m_iActivePlayer = iPlayerIndex; } ++iPlayerIndex; PlayerInfo playerInfo; playerInfo.m_eLeader = player.getLeaderType(); playerInfo.m_eCivilization = player.getCivilizationType(); playerInfo.m_eDifficulty = player.getHandicapType(); playerInfo.m_strCustomLeaderName = player.getName(); playerInfo.m_strCustomCivilizationName = player.getCivilizationDescription(); playerInfo.m_strCustomCivilizationShortName = player.getCivilizationShortDescription(); playerInfo.m_strCustomCivilizationAdjective = player.getCivilizationAdjective(); playerInfo.m_ePlayerColor = player.getPlayerColor(); TurnDataSets dataSet(m_dataSetMap.size()); unsigned int uiNumDataSets = player.getNumReplayDataSets(); for(unsigned int uiPlayerDataSet = 0; uiPlayerDataSet < uiNumDataSets; ++uiPlayerDataSet) { // First, Locate the index of the dataset std::string playerDataSetName = player.getReplayDataSetName(uiPlayerDataSet); unsigned int uiDataSet = 0; bool bFound = false; for(uiDataSet = 0; uiDataSet < m_dataSetMap.size(); ++uiDataSet) { const std::string& dataSetName = m_dataSetMap[uiDataSet]; if(dataSetName == playerDataSetName) { bFound = true; break; } } // Add a new index if one doesn't exist. if(!bFound) { m_dataSetMap.push_back(playerDataSetName); dataSet.push_back(TurnData()); uiDataSet = m_dataSetMap.size() - 1; } CvPlayer::TurnData playerData = player.getReplayDataHistory(uiPlayerDataSet); TurnData turnData; for(CvPlayer::TurnData::iterator it = playerData.begin(); it != playerData.end(); ++it) { turnData[(*it).first - m_iInitialTurn] = (*it).second; } dataSet[uiDataSet] = turnData; } m_listPlayerDataSets.push_back(dataSet); m_listPlayerInfo.push_back(playerInfo); } } m_listReplayMessages.clear(); const uint nMessages = game.getNumReplayMessages(); m_listReplayMessages.reserve(nMessages); for(uint i = 0; i < nMessages; ++i) { const CvReplayMessage* pMessage = game.getReplayMessage(i); if(pMessage) { CvReplayMessage modifiedMessage = (*pMessage); modifiedMessage.setPlayer((PlayerTypes)mapPlayers[modifiedMessage.getPlayer()]); m_listReplayMessages.push_back(modifiedMessage); } } CvMap& kMap = GC.getMap(); m_iMapWidth = kMap.getGridWidth(); m_iMapHeight = kMap.getGridHeight(); int numPlots = kMap.numPlots(); m_listPlots.clear(); m_listPlots.reserve(numPlots); for(int i = 0; i < numPlots; i++) { PlotState plotState; CvPlot* pkPlot = kMap.plotByIndexUnchecked(i); plotState.m_ePlotType = pkPlot->getPlotType(); plotState.m_eTerrain = pkPlot->getTerrainType(); plotState.m_eFeature = pkPlot->getFeatureType(); plotState.m_bNEOfRiver = pkPlot->isNEOfRiver(); plotState.m_bWOfRiver = pkPlot->isWOfRiver(); plotState.m_bNWOfRiver = pkPlot->isNWOfRiver(); PlotStatePerTurn plotStatePerTurn; plotStatePerTurn[m_iFinalTurn] = plotState; m_listPlots.push_back(plotStatePerTurn); } }
vtkDataArray & ImageDataObject::scalars() { auto s = dataSet()->GetPointData()->GetScalars(); assert(s && s->GetName()); return *s; }
void ImageDataObject::addDataArray(vtkDataArray & dataArray) { dataSet()->GetPointData()->AddArray(&dataArray); }
void ClassifyRFSharedCommand::processSharedAndDesignData(vector<SharedRAbundVector*> lookup){ try { map<string, int> treatmentToIntMap; map<int, string> intToTreatmentMap; //vector<string> groups = designMap.getCategory(); for (int i = 0; i < lookup.size(); i++) { string treatmentName = designMap.get(lookup[i]->getGroup()); treatmentToIntMap[treatmentName] = i; intToTreatmentMap[i] = treatmentName; } int numSamples = lookup.size(); int numFeatures = lookup[0]->getNumBins(); int numRows = numSamples; int numColumns = numFeatures + 1; // extra one space needed for the treatment/outcome vector< vector<int> > dataSet(numRows, vector<int>(numColumns, 0)); vector<string> names; for (int i = 0; i < lookup.size(); i++) { string sharedGroupName = lookup[i]->getGroup(); names.push_back(sharedGroupName); string treatmentName = designMap.get(sharedGroupName); int j = 0; for (; j < lookup[i]->getNumBins(); j++) { int otuCount = lookup[i]->get(j); dataSet[i][j] = otuCount; } dataSet[i][j] = treatmentToIntMap[treatmentName]; } RandomForest randomForest(dataSet, numDecisionTrees, treeSplitCriterion, doPruning, pruneAggressiveness, discardHighErrorTrees, highErrorTreeDiscardThreshold, optimumFeatureSubsetSelectionCriteria, featureStandardDeviationThreshold); randomForest.populateDecisionTrees(); randomForest.calcForrestErrorRate(); randomForest.printConfusionMatrix(intToTreatmentMap); map<string, string> variables; variables["[filename]"] = outputDir + util.getRootName(util.getSimpleName(sharedfile)) + "RF."; variables["[distance]"] = lookup[0]->getLabel(); string filename = getOutputFileName("summary", variables); outputNames.push_back(filename); outputTypes["summary"].push_back(filename); randomForest.calcForrestVariableImportance(filename); // map<string, string> variable; variable["[filename]"] = outputDir + util.getRootName(util.getSimpleName(sharedfile)) + "misclassifications."; variable["[distance]"] = lookup[0]->getLabel(); string mc_filename = getOutputFileName("summary", variable); outputNames.push_back(mc_filename); outputTypes["summary"].push_back(mc_filename); randomForest.getMissclassifications(mc_filename, intToTreatmentMap, names); // m->mothurOutEndLine(); } catch(exception& e) { m->errorOut(e, "ClassifySharedCommand", "processSharedAndDesignData"); exit(1); } }
// cnn face detection test void cnnFaceDetectionTest() { // configuration string imgPath = "Z:\\User\\wuxiang\\data\\face_detection\\FDDB\\originalPics"; string listPath = "Z:\\User\\wuxiang\\data\\face_detection\\FDDB\\FDDB_list.txt"; string frPath = "Z:\\Temp\\CNN_Face_Detection\\fr\\man"; string bingModelPath = "D:\\svn\\Algorithm\\wuxiang\\Code\\C\\BING\\model\\ObjNessB2W8MAXBGR.wS1"; string cnnModelPath = "D:\\svn\\Algorithm\\wuxiang\\Code\\C\\BING\\model\\36_detection.bin"; string savePath = "D:\\BING\\36_net\\fr"; const int W = 8, NSS = 2, numPerSz = 150; const int netSize = 36, netProbLayer = 7; const float thr = 0.4; vector<Vec4i> boxTestStageI; ValStructVec<float, Vec4i> boxTestStageII; ValStructVec<float, Vec4i> box; char fr[_MAX_PATH]; // load image DataSet dataSet(imgPath, listPath, frPath); dataSet.loadAnnotations(); // predict ObjectnessTest objectNessTest(dataSet, bingModelPath, W, NSS); objectNessTest.loadTrainedModel(bingModelPath); CnnFace cnn(cnnModelPath, netSize, netProbLayer); cnn.loadTrainedModel(); #pragma openmp parallel for for(int i = 0; i < dataSet.testNum; i++) { // face detection Stage I: get face region proposal boxTestStageI.clear(); printf("Process %d images..\n", i); CmTimer tm("Predict"); tm.Start(); Mat img = imread(dataSet.imgPath + "\\" + dataSet.imgPathName[i]); boxTestStageI.reserve(10000); objectNessTest.getFaceProposaksForPerImgFast(img, boxTestStageI, numPerSz); // cnn cnn.getFaceDetectionPerImg(img, boxTestStageI, boxTestStageII, thr); // nms cnn.nonMaxSup(boxTestStageII, box, 0.2); tm.Stop(); printf("Predicting an image is %gs\n", tm.TimeInSeconds()); // save sprintf(fr, "%s/%s", savePath.c_str(), dataSet.imgPathFr[i].c_str()); create_directory_from_filename(fr); FILE *fp = fopen(fr, "wt"); fprintf(fp, "%d\n", box.size()); for (int j = 0; j < box.size(); j++) { Vec4i &out = box[j]; fprintf(fp, "%d\t%d\t%d\t%d\t%f\n", out[0], out[1], out[2], out[3], box(j)); } fclose(fp); img.~Mat(); } }
// BING test code void RunFaceProposal(int W, int NSS, int numPerSz) { // configuration string imgPath = "Z:\\User\\wuxiang\\data\\face_detection\\FDDB\\originalPics"; string listPath = "Z:\\User\\wuxiang\\data\\face_detection\\FDDB\\FDDB_list.txt"; string frPath = "Z:\\Temp\\CNN_Face_Detection\\fr\\man"; string modelPath = "D:\\svn\\Algorithm\\wuxiang\\Code\\C\\BING\\model\\ObjNessB2W8MAXBGR.wS1"; string savePath = "D:\\BING\\Proposal\\fr"; #if ILLUSTRATE == 1 string saveErrorPath = "D:\\BING\\Proposal\\error"; string saveImgPath = "D:\\BING\\Proposal\\img"; FILE *list = fopen((saveErrorPath+"\\"+"list.txt").c_str(), "wt"); #endif vector<vector<Vec4i>> frsImgs; char fr[_MAX_PATH]; // load image DataSet dataSet(imgPath, listPath, frPath); dataSet.loadAnnotations(); // predict ObjectnessTest objectNessTest(dataSet, modelPath, W, NSS); objectNessTest.loadTrainedModel(modelPath); objectNessTest.getFaceProposalsForImgsFast(frsImgs, numPerSz); // save for (int i = 0; i < frsImgs.size(); i++) { //cout << dataSet.imgPathFr[i].c_str() << "is saving" <<endl; sprintf(fr, "%s/%s", savePath.c_str(), dataSet.imgPathFr[i].c_str()); create_directory_from_filename(fr); FILE *fp = fopen(fr, "wt"); fprintf(fp, "%d\n", frsImgs[i].size()); for (int j = 0; j < frsImgs[i].size(); j++) { Vec4i box = frsImgs[i][j]; fprintf(fp, "%d\t%d\t%d\t%d\n", box[0], box[1], box[2], box[3]); } fclose(fp); // illustrate #if ILLUSTRATE == 1 ValStructVec<float, Vec4i> box; box.reserve(frsImgs[i].size()); string imgSavePath = saveImgPath + "\\" + dataSet.imgPathName[i] + "_Match.jpg"; create_directory_from_filename(imgSavePath.c_str()); objectNessTest.illuTestReults(imgPath + "\\" + dataSet.imgPathName[i], imgSavePath, dataSet.imgFr[i], frsImgs[i], box); if (box.size() == 0) continue; char error[_MAX_PATH]; sprintf(error, "%s/%s", saveErrorPath.c_str(), dataSet.imgPathFr[i].c_str()); create_directory_from_filename(error); FILE *errorFp = fopen(error, "wt"); fprintf(errorFp, "%d\n", box.size()); for (int j = 0; j < box.size(); j++) { Vec4i out = box[j]; fprintf(errorFp, "%d\t%d\t%d\t%d\t%f\n", out[0], out[1], out[2], out[3], box(j)); } fclose(errorFp); fprintf(list, "%s\n", dataSet.imgPathName[i].c_str()); #endif } #if ILLUSTRATE == 1 fclose(list); #endif }