bool ccVolumeCalcTool::showGridBoxEditor() { if (cc2Point5DimEditor::showGridBoxEditor()) { updateGridInfo(); return true; } return false; }
bool ccRasterizeTool::showGridBoxEditor() { if (cc2Point5DimEditor::showGridBoxEditor()) { updateGridInfo(); return true; } return false; }
void Human::moveModel2SingleTrack() //(double randr, double randt, double angle, double moveP, double revisitP) { //init moving if (visitedLocations.empty()) { visitedLocations.push_back(currentMapPosition); } //double r = uniRand.value(); double x0 = 1; double x1 = 1000; //range from 0 to 1000m double alpha = -1.55; //alpha = -1.75; double rho = 0.1; double gamma = -0.21; //gamma = -0.2; double randr = uRandR.value(); double powerLawR = pow(((pow(x1, alpha+1) - pow(x0, alpha+1))*randr + pow(x0, alpha+1)), 1/(alpha+1)); //jump size double Pnew = rho * pow((double)visitedLocations.size(), gamma); //Exploration probability //double t = uniRand.value(); double t0 = 1; double t1 = 17*3600; //range from 0 to 17 hours double beta = -1.8; double randt = uRandT.value(); powerLawT = pow(((pow(t1, beta+1) - pow(t0, beta+1))*randt + pow(t0, beta+1)), 1/(beta+1)); //waiting time //double moveP = uniRand.value(); //double newX = currentMapPosition.position.x + powerLawR*cos(angle*PI/180); //double newY = currentMapPosition.position.y + powerLawR*sin(angle*PI/180); double moveP = uRandM.value(); double angle = uRandA.value(); if (moveP <= Pnew) { //Explore a new location double newX = currentMapPosition.position.x + powerLawR*cos(angle*PI/180.0); double newY = currentMapPosition.position.y + powerLawR*sin(angle*PI/180.0); int loopTimes = 0; while ((newX < 0 || newY < 0 || newX > field->maxX || newY > field->maxY) && loopTimes < 4) { angle += 90; newX = currentMapPosition.position.x + powerLawR*cos(angle*PI/180.0); newY = currentMapPosition.position.y + powerLawR*sin(angle*PI/180.0); ++loopTimes; } if (newX < 0) newX = 0; if (newY < 0) newY = 0; if (newX > field->maxX) newX = field->maxX; if (newY > field->maxY) newY = field->maxY; Point tp(newX, newY); Point preLocation = currentMapPosition.position; currentMapPosition.position = tp; //gravity model int gNum = this->inGrid(GRID_SIZE); int rho_r = field->gridPool[gNum].humanNum; double Cr = rho_r+RHO_0; if (Cr <= 0) Cr = 1; powerLawR = powerLawR*pow(Cr, alpha); newX = preLocation.x + powerLawR*cos(angle*PI/180.0); newY = preLocation.y + powerLawR*sin(angle*PI/180.0); loopTimes = 0; while ((newX < 0 || newY < 0 || newX > field->maxX || newY > field->maxY) && loopTimes < 4) { angle += 90; newX = preLocation.x + powerLawR*cos(angle*PI/180.0); newY = preLocation.y + powerLawR*sin(angle*PI/180.0); ++loopTimes; } if (newX < 0) newX = 0; if (newY < 0) newY = 0; if (newX > field->maxX) newX = field->maxX; if (newY > field->maxY) newY = field->maxY; currentMapPosition.position.x = newX; currentMapPosition.position.y = newY; ////////////////////////////////////////////////////// currentMapPosition.visitFrequency = 1; userVisitedRecord.insert(make_pair(1, currentMapPosition)); visitedLocations.push_back(currentMapPosition); updateGridInfo(); } else { //Go back to some places that the user visited multimap<int, Maplocation>::iterator lvpos; //location visited pos int totalVisit = 0; for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { totalVisit += lvpos->first; } multimap<double, Maplocation> distribution; //probability, location double preProb = 0; for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { double prob = (double)lvpos->first/totalVisit; distribution.insert(make_pair(preProb+prob, lvpos->second)); preProb += prob; } //test multimap<double, Maplocation>::iterator dispos = distribution.end(); --dispos; assert(dispos->first - 1 <= 0.00001); //end test //search the revisit location double revisitP = uRandV.value(); for (dispos = distribution.begin(); dispos != distribution.end(); ++dispos) { if (revisitP <= dispos->first) { //this is the target currentMapPosition = dispos->second; //for updating visitedLocations to output St and fk for (int i = 0; i < visitedLocations.size(); ++i) { if (visitedLocations[i] == currentMapPosition) { visitedLocations[i].visitFrequency++; } } //locate the corresponding location and update visited times for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { if (lvpos->second == dispos->second) { int value = lvpos->first; Maplocation m = lvpos->second; userVisitedRecord.erase(lvpos); ++value; userVisitedRecord.insert(make_pair(value, m)); break; } } break; } } } timePassed += powerLawT; waitingTimeSequence.push_back(make_pair(timePassed, visitedLocations.size())); }
void Human::moveModel2() //(double randr, double randt, double angle, double moveP, double revisitP) { //init moving if (userVisitedRecord.empty()) { userVisitedRecord.insert(make_pair(1, currentMapPosition)); } //if it does not wait, compute wating time after moving if (!waitNow && !readyToMove) { double t0 = 1; //double t1 = 17*3600; //range from 0 to 17 hours double t1 = 4000; double beta = -1.8; double randt = uRandT.value(); powerLawT = pow(((pow(t1, beta+1) - pow(t0, beta+1))*randt + pow(t0, beta+1)), 1/(beta+1)); //waiting time timeCounter = powerLawT; waitNow = true; } //if ready to move, compute jump distance. Otherwise, wait if (waitNow && !readyToMove) { timeCounter -= UPDATE_TIME_UNIT; if (timeCounter <= 0) { waitNow = false; readyToMove = true; } else waitNow = true; } else { readyToMove = false; double x0 = 1; double x1 = 500; //range from 0 to x1 meters double alpha = -1.55; //n //alpha = -1.75; double rho = 0.1; double gamma = -0.21; //gamma = -0.2; double randr = uRandR.value(); double powerLawR = pow(((pow(x1, alpha+1) - pow(x0, alpha+1))*randr + pow(x0, alpha+1)), 1/(alpha+1)); //jump size 1 //field->deltaR.insert(powerLawR); double Pnew = rho * pow((double)userVisitedRecord.size(), gamma); //Exploration probability if (userVisitedRecord.empty()) { cout << "userVisitedRecord is empty" << endl; exit(2); } double moveP = uRandM.value(); double angle = uRandA.value(); if (moveP <= Pnew) { //Explore a new location readyToMove = false; double newX = currentMapPosition.position.x + powerLawR*cos(angle*PI/180.0); double newY = currentMapPosition.position.y + powerLawR*sin(angle*PI/180.0); int loopTimes = 0; while ((newX < 0 || newY < 0 || newX > field->maxX || newY > field->maxY) && loopTimes < 4) { angle += 90; newX = currentMapPosition.position.x + powerLawR*cos(angle*PI/180.0); newY = currentMapPosition.position.y + powerLawR*sin(angle*PI/180.0); ++loopTimes; } if (newX < 0) newX = 0; if (newY < 0) newY = 0; if (newX > field->maxX) newX = field->maxX; if (newY > field->maxY) newY = field->maxY; Point tp(newX, newY); Point preLocation = currentMapPosition.position; currentMapPosition.position = tp; //gravity model int gNum = this->inGrid(GRID_SIZE); if (gNum < 0 || gNum >= 1000000) { cout << "Grid number is wrong" << endl; exit(2); } int rho_r = field->gridPool[gNum].humanNum; double Cr = rho_r+RHO_0; if (Cr <= 0) Cr = 1; powerLawR = powerLawR*pow(Cr, alpha); newX = preLocation.x + powerLawR*cos(angle*PI/180.0); newY = preLocation.y + powerLawR*sin(angle*PI/180.0); loopTimes = 0; while ((newX < 0 || newY < 0 || newX > field->maxX || newY > field->maxY) && loopTimes < 4) { angle += 90; newX = preLocation.x + powerLawR*cos(angle*PI/180.0); newY = preLocation.y + powerLawR*sin(angle*PI/180.0); ++loopTimes; } if (newX < 0) newX = 0; if (newY < 0) newY = 0; if (newX > field->maxX) newX = field->maxX; if (newY > field->maxY) newY = field->maxY; currentMapPosition.position.x = newX; currentMapPosition.position.y = newY; ////////////////////////////////////////////////////// currentMapPosition.visitFrequency = 1; userVisitedRecord.insert(make_pair(1, currentMapPosition)); updateGridInfo(); } else { //Go back to some places that the user visited //Point tempLocation(newX, newY); /* //find the nearest visited location double minD = 0xffff; int target = 0; for (int i = 0; i < visitedLocations.size(); ++i) { double Dis = tempLocation.distance(visitedLocations[i].position); if (Dis < minD) { minD = Dis; target = i; } } visitedLocations[target].visitFrequency++; currentMapPosition = visitedLocations[target]; */ multimap<int, Maplocation>::iterator lvpos; //location visited pos int totalVisit = 0; for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { totalVisit += lvpos->first; } if (totalVisit == 0 || userVisitedRecord.empty()) { cout << "totalVisit = 0" << endl; exit(2); } multimap<double, Maplocation> distribution; //probability, location double preProb = 0; for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { double prob = (double)lvpos->first/totalVisit; Maplocation ml = lvpos->second; distribution.insert(make_pair(preProb+prob, ml)); preProb += prob; } //test multimap<double, Maplocation>::iterator dispos = distribution.end(); --dispos; if(distribution.empty() || dispos->first - 1 > 0.00001) { cout << "Final prob is " << dispos->first << endl; exit(2); } //end test //search the revisit location double revisitP = uRandV.value(); for (dispos = distribution.begin(); dispos != distribution.end(); ++dispos) { if (revisitP <= dispos->first) { //this is the target if (currentMapPosition != dispos->second) { currentMapPosition = dispos->second; readyToMove = false; //locate the corresponding location and update visited times for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { if (lvpos->second == dispos->second) { int value = lvpos->first; Maplocation m = lvpos->second; userVisitedRecord.erase(lvpos); ++value; userVisitedRecord.insert(make_pair(value, m)); break; } } break; } } } //if (TIME_UNIT_COUNTER == 11500 && this->index == 713168) // cout << "Return" << endl; updateGridInfo(); } } }
//time unit version void Human::moveModel1() //(double randr, double randt, double angle, double moveP, double revisitP) { //init moving if (userVisitedRecord.empty()) { userVisitedRecord.insert(make_pair(1, currentMapPosition)); } //double powerLawT = 0; //double timeCounter = 0; //if it does not wait, compute wating time after moving if (!waitNow) { double t0 = 1; double t1 = 17*3600; //range from 0 to 17 hours double beta = -1.8; double randt = uRandT.value(); powerLawT = pow(((pow(t1, beta+1) - pow(t0, beta+1))*randt + pow(t0, beta+1)), 1/(beta+1)); //waiting time timeCounter = powerLawT; waitNow = true; } //if ready to move, compute jump distance. Otherwise, wait if (waitNow && !readyToMove) { timeCounter -= UPDATE_TIME_UNIT; if (timeCounter <= 0) { waitNow = false; readyToMove = true; } else waitNow = true; } else { readyToMove = false; double x0 = 1; double x1 = 1000; //range from 0 to x1 meters double alpha = -1.55; double rho = 0.1; double gamma = -0.21; double randr = uRandR.value(); double powerLawR = pow(((pow(x1, alpha+1) - pow(x0, alpha+1))*randr + pow(x0, alpha+1)), 1/(alpha+1)); //jump size double Pnew = rho * pow((double)userVisitedRecord.size(), gamma); //Exploration probability double moveP = uRandM.value(); double angle = uRandA.value(); if (moveP <= Pnew) { //Explore a new location readyToMove = false; double newX = currentMapPosition.position.x + powerLawR*cos(angle*PI/180); double newY = currentMapPosition.position.y + powerLawR*sin(angle*PI/180); Point tp(newX, newY); currentMapPosition.position = tp; currentMapPosition.visitFrequency = 1; userVisitedRecord.insert(make_pair(1, currentMapPosition)); updateGridInfo(); //record every jump step and update all corresponding information } else { //Go back to some places that the user visited /* Point tempLocation(newX, newY); //find the nearest visited location double minD = 0xffff; int target = 0; for (int i = 0; i < visitedLocations.size(); ++i) { double Dis = tempLocation.distance(visitedLocations[i].position); if (Dis < minD) { minD = Dis; target = i; } } visitedLocations[target].visitFrequency++; currentMapPosition = visitedLocations[target]; */ multimap<int, Maplocation>::iterator lvpos; //location visited pos int totalVisit = 0; for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { totalVisit += lvpos->first; } multimap<double, Maplocation> distribution; //probability, location double preProb = 0; for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { double prob = (double)lvpos->first/totalVisit; distribution.insert(make_pair(preProb+prob, lvpos->second)); preProb += prob; } //test multimap<double, Maplocation>::iterator dispos = distribution.end(); --dispos; assert(dispos->first - 1 <= 0.00001); //end test //search the revisit location double revisitP = uRandV.value(); for (dispos = distribution.begin(); dispos != distribution.end(); ++dispos) { if (revisitP <= dispos->first) { //this is the target if (currentMapPosition != dispos->second) { currentMapPosition = dispos->second; readyToMove = false; } //locate the corresponding location and update visited times for (lvpos = userVisitedRecord.begin(); lvpos != userVisitedRecord.end(); ++lvpos) { if (lvpos->second == dispos->second) { int value = lvpos->first; Maplocation m = lvpos->second; userVisitedRecord.erase(lvpos); ++value; userVisitedRecord.insert(make_pair(value, m)); break; } } break; } } updateGridInfo(); } } //waitingTimeSequence.push_back(make_pair(powerLawT, visitedLocations.size())); }
ccVolumeCalcTool::ccVolumeCalcTool(ccGenericPointCloud* cloud1, ccGenericPointCloud* cloud2, QWidget* parent/*=0*/) : QDialog(parent, Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint) , cc2Point5DimEditor() , Ui::VolumeCalcDialog() , m_cloud1(cloud1) , m_cloud2(cloud2) { setupUi(this); connect(buttonBox, SIGNAL(accepted()), this, SLOT(saveSettingsAndAccept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(gridStepDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateGridInfo())); connect(gridStepDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(gridOptionChanged())); connect(groundEmptyValueDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(gridOptionChanged())); connect(ceilEmptyValueDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(gridOptionChanged())); connect(projDimComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(projectionDirChanged(int))); connect(updatePushButton, SIGNAL(clicked()), this, SLOT(updateGridAndDisplay())); connect(heightProjectionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(gridOptionChanged())); connect(fillGroundEmptyCellsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(groundFillEmptyCellStrategyChanged(int))); connect(fillCeilEmptyCellsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(ceilFillEmptyCellStrategyChanged(int))); connect(swapToolButton, SIGNAL(clicked()), this, SLOT(swapRoles())); connect(groundComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(groundSourceChanged(int))); connect(ceilComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(ceilSourceChanged(int))); connect(clipboardPushButton, SIGNAL(clicked()), this, SLOT(exportToClipboard())); connect(exportGridPushButton, SIGNAL(clicked()), this, SLOT(exportGridAsCloud())); connect(precisionSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setDisplayedNumberPrecision(int))); if (m_cloud1 && !m_cloud2) { //the existing cloud is always the second by default std::swap(m_cloud1, m_cloud2); } assert(m_cloud2); //custom bbox editor ccBBox gridBBox = m_cloud1 ? m_cloud1->getOwnBB() : ccBBox(); if (m_cloud2) { gridBBox += m_cloud2->getOwnBB(); } if (gridBBox.isValid()) { createBoundingBoxEditor(gridBBox, this); connect(editGridToolButton, SIGNAL(clicked()), this, SLOT(showGridBoxEditor())); } else { editGridToolButton->setEnabled(false); } groundComboBox->addItem("Constant"); ceilComboBox->addItem("Constant"); if (m_cloud1) { groundComboBox->addItem(m_cloud1->getName()); ceilComboBox->addItem(m_cloud1->getName()); } if (m_cloud2) { groundComboBox->addItem(m_cloud2->getName()); ceilComboBox->addItem(m_cloud2->getName()); } assert(groundComboBox->count() >= 2); groundComboBox->setCurrentIndex(groundComboBox->count()-2); ceilComboBox->setCurrentIndex(ceilComboBox->count()-1); //add window create2DView(mapFrame); if (m_glWindow) { ccGui::ParamStruct params = m_glWindow->getDisplayParameters(); params.colorScaleShowHistogram = false; params.displayedNumPrecision = precisionSpinBox->value(); m_glWindow->setDisplayParameters(params, true); } loadSettings(); updateGridInfo(); gridIsUpToDate(false); }
void ccVolumeCalcTool::projectionDirChanged(int dir) { updateGridInfo(); gridIsUpToDate(false); }
ccRasterizeTool::ccRasterizeTool(ccGenericPointCloud* cloud, QWidget* parent/*=0*/) : QDialog(parent, Qt::WindowMaximizeButtonHint) , cc2Point5DimEditor() , Ui::RasterizeToolDialog() , m_cloud(cloud) { setupUi(this); #ifndef CC_GDAL_SUPPORT generateRasterPushButton->setDisabled(true); generateRasterPushButton->setChecked(false); #endif connect(buttonBox, SIGNAL(accepted()), this, SLOT(testAndAccept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(testAndReject())); connect(gridStepDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateGridInfo())); connect(gridStepDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(gridOptionChanged())); connect(emptyValueDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(gridOptionChanged())); connect(resampleCloudCheckBox, SIGNAL(toggled(bool)), this, SLOT(gridOptionChanged())); connect(dimensionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(projectionDirChanged(int))); connect(heightProjectionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(projectionTypeChanged(int))); connect(scalarFieldProjection, SIGNAL(currentIndexChanged(int)), this, SLOT(sfProjectionTypeChanged(int))); connect(fillEmptyCellsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(fillEmptyCellStrategyChanged(int))); connect(updateGridPushButton, SIGNAL(clicked()), this, SLOT(updateGridAndDisplay())); connect(generateCloudPushButton, SIGNAL(clicked()), this, SLOT(generateCloud())); connect(generateImagePushButton, SIGNAL(clicked()), this, SLOT(generateImage())); connect(generateRasterPushButton, SIGNAL(clicked()), this, SLOT(generateRaster())); connect(generateASCIIPushButton, SIGNAL(clicked()), this, SLOT(generateASCIIMatrix())); connect(generateMeshPushButton, SIGNAL(clicked()), this, SLOT(generateMesh())); connect(generateContoursPushButton, SIGNAL(clicked()), this, SLOT(generateContours())); connect(exportContoursPushButton, SIGNAL(clicked()), this, SLOT(exportContourLines())); connect(clearContoursPushButton, SIGNAL(clicked()), this, SLOT(removeContourLines())); connect(activeLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(activeLayerChanged(int))); //custom bbox editor ccBBox gridBBox = m_cloud ? m_cloud->getOwnBB() : ccBBox(); if (gridBBox.isValid()) { createBoundingBoxEditor(gridBBox, this); connect(editGridToolButton, SIGNAL(clicked()), this, SLOT(showGridBoxEditor())); } else { editGridToolButton->setEnabled(false); } if (m_cloud) { cloudNameLabel->setText(m_cloud->getName()); pointCountLabel->setText(QString::number(m_cloud->size())); interpolateSFFrame->setEnabled(cloud->hasScalarFields()); //populate layer box activeLayerComboBox->addItem(GetDefaultFieldName(PER_CELL_HEIGHT)); if (cloud->isA(CC_TYPES::POINT_CLOUD) && cloud->hasScalarFields()) { ccPointCloud* pc = static_cast<ccPointCloud*>(cloud); for (unsigned i=0; i<pc->getNumberOfScalarFields(); ++i) activeLayerComboBox->addItem(pc->getScalarField(i)->getName()); } else { activeLayerComboBox->setEnabled(false); } //add window create2DView(mapFrame); } loadSettings(); updateGridInfo(); gridIsUpToDate(false); }
void ccRasterizeTool::projectionDirChanged(int dir) { updateGridInfo(); gridIsUpToDate(false); }