void OnlinePlotter::eventOccured(Event *event) { if(event == 0) { return; } else if(event == mStartEvent) { if(mPlotterProgramValue->get() == "" || mPlotterProgramValue->get().contains("internal", Qt::CaseInsensitive)) { mRunningCalculator = mActiveCalculatorValue->get(); prepareData(mRunningCalculator); emit startProcessing(); } } else if(event == mFinishEvent) { //if the calculator stopped running: if(mPlotterProgramValue->get() == "" || mPlotterProgramValue->get().contains("internal", Qt::CaseInsensitive)) { emit finishedProcessing(); } } }
double ProblemDescription::evaluateConstraint( const double * xi, double * h, double * H ) { if ( factory.empty() ) {return 0; } TIMER_START( "constraint" ); assert( h ); // make sure that h is not NULL prepareData( xi ); MatMap h_map( h, factory.numOutput(), 1 ); if ( !H ){ const double val = factory.evaluate( trajectory, h_map ); TIMER_STOP( "constraint" ); return val; } MatMap H_map( H, trajectory.size(), factory.numOutput() ); double magnitude = factory.evaluate(trajectory, h_map, H_map ); if( doing_covariant ){ //TODO find out if this is correct MatMap H_map2( H, trajectory.N(), trajectory.M()*factory.numOutput() ); metric.multiplyLowerInverse( H_map2 ); } TIMER_STOP( "constraint" ); return magnitude; }
/** * Copy the sorting parameters from the specified view, and apply both those * and its current filter. * * @param otherView The view whose properties are to be mimicked */ void View::copyStateFrom(View *otherView) { sortColumn = otherView->sortColumn; sortOrder = otherView->sortOrder; sortName = otherView->sortName; prepareData(); }
void ImageConverter::setOutFormat(int format) { DPTR_D(ImageConverter); if (d.fmt_out == format) return; d.fmt_out = format; prepareData(); }
bool ImageConverter::convert(const quint8 * const src[], const int srcStride[]) { DPTR_D(ImageConverter); if (d.update_data && !prepareData()) { qWarning("prepair output data error"); return false; } return convert(src, srcStride, (uint8_t**)d.bits.constData(), d.pitchs.constData()); }
void ImageConverter::setOutSize(int width, int height) { DPTR_D(ImageConverter); if (d.w_out == width && d.h_out == height) return; d.w_out = width; d.h_out = height; prepareData(); }
void ImageConverter::setOutFormat(int format) { DPTR_D(ImageConverter); if (d.fmt_out == format) return; d.fmt_out = (AVPixelFormat)format; d.update_data = true; prepareData(); }
/** * return 1 if OK, return 0 if error */ int LR::evaluate(float &slope,float &avgY){ int res = 0; int items; struct Point *data = prepareData (items); if (items > 2 && data != NULL){ slope = leastSqrRegression(data, items); avgY = this->AVGy; res = 1; } delete data; return res; }
double ProblemDescription::evaluateObjective ( const double * xi, double * g ) { TIMER_START( "gradient" ); if ( xi ){ prepareData( xi ); } else { prepareData(); } double value; if ( g ) { value = computeObjective( MatMap(g, trajectory.N(), trajectory.M() ) ); } else { value = computeObjective( MatX(0,0) ); } TIMER_STOP( "gradient" ); return value; }
void game::play ( ) { startUp (); while (m_gameaction != gameaction::Exit) { m_rw.clear (sf::Color::Green); prepareData (); prepareScreenElements (); draw (m_ses, m_rw); m_rw.display (); handleEvents (); } shutDown (); }
double ProblemDescription::evaluateConstraint( MatX & h ) { if ( factory.empty() ) {return 0; } TIMER_START( "constraint" ); prepareData(); h.resize( factory.numOutput(), 1 ); const double value = factory.evaluate( trajectory, h); TIMER_STOP( "constraint" ); return value; }
void CurioDuinoData::update() { // update edge sensors sensors.read(sensor_values); // update data struct leftEdge = (sensor_values[0] > QTR_THRESHOLD); rightEdge = (sensor_values[1] > QTR_THRESHOLD); battery = analogRead(BATTERY_SENSOR); leftObstacle = (!digitalRead(LEFT_OBST_SENSOR)); middleObstacle = (!digitalRead(MIDDLE_OBST_SENSOR)); rightObstacle = (!digitalRead(RIGHT_OBST_SENSOR)); leftForward = (!digitalRead(DIR_L)); rightForward = (!digitalRead(DIR_R)); prepareData(); }
void Z3DAxis::render(Z3DEye eye) { if (!m_showAxis.get()) return; prepareData(eye); if (m_mode.get() == "Arrow") m_rendererBase->activateRenderer(m_arrowRenderer, m_fontRenderer); else m_rendererBase->activateRenderer(m_lineRenderer, m_fontRenderer); glm::ivec4 viewport = m_rendererBase->getViewport(); int size = std::min(viewport.z, viewport.w) * m_axisRegionRatio.get(); glViewport(viewport.x, viewport.y, size, size); m_rendererBase->render(eye); glViewport(viewport.x, viewport.y, viewport.z, viewport.w); }
Ptr<TrackerTargetState> TrackerStateEstimatorMILBoosting::estimateImpl( const std::vector<ConfidenceMap>& /*confidenceMaps*/) { //run ClfMilBoost classify in order to compute next location if( currentConfidenceMap.empty() ) return Ptr<TrackerTargetState>(); Mat positiveStates; Mat negativeStates; prepareData( currentConfidenceMap, positiveStates, negativeStates ); std::vector<float> prob = boostMILModel.classify( positiveStates ); int bestind = max_idx( prob ); //float resp = prob[bestind]; return currentConfidenceMap.at( bestind ).first; }
double ProblemDescription::evaluateCollisionFunction( const double * xi, double * g) { //TODO throw error. assert( collision_function ); prepareData( xi ); double value; if ( g ){ MatMap g_map( g, N(), M() ); value = collision_function->evaluate( trajectory, g_map ); if ( doing_covariant ){ metric.multiplyLowerInverse( g_map ); } }else { value = collision_function->evaluate( trajectory ); } return value; }
void TrackerStateEstimatorMILBoosting::updateImpl( std::vector<ConfidenceMap>& confidenceMaps ) { if( !trained ) { //this is the first time that the classifier is built //init MIL boostMILModel.init(); trained = true; } ConfidenceMap lastConfidenceMap = confidenceMaps.back(); Mat positiveStates; Mat negativeStates; prepareData( lastConfidenceMap, positiveStates, negativeStates ); //update MIL boostMILModel.update( positiveStates, negativeStates ); }
double ProblemDescription::evaluateConstraint( MatX & h, MatX & H ) { if ( factory.empty() ) {return 0; } TIMER_START( "constraint" ); prepareData(); h.resize( factory.numOutput(), 1 ); H.resize( size(), factory.numOutput() ); double magnitude = factory.evaluate( trajectory, h, H ); if ( doing_covariant ) { metric.multiplyLowerInverse( MatMap ( H.data(), trajectory.N(), trajectory.M()*factory.numOutput() ) ); } TIMER_STOP( "constraint" ); return magnitude; }
void LMRecorder::onFrame(const Leap::Controller& c) { ScopedLock frameLock(frameMutex); ScopedLock closingLock(closingMutex); if (currentFrame !=NULL) { delete currentFrame; currentFrame = NULL; } currentFrame = new GestureFrame(); clock_gettime(CLOCK_REALTIME, &t2); timestamp = (double)(t2.tv_sec - t1.tv_sec) + 1.e-9*(t2.tv_nsec - t1.tv_nsec); timestamp *= 1000; prepareData(c.frame(), currentFrame, timestamp); gestureStorageDriver->saveGestureFrame(*currentFrame); printf("F: %d T: %dms FPS: %.2f FPS_AVG: %.2f\n", count, (int)(timestamp), 1000.0/(timestamp-lastTime), 1000*count/timestamp); lastTime = timestamp; count++; notifyListeners(); }
CylinderModel::CylinderModel(float topRadius):mTopRadius(topRadius) { prepareData(); }
/** * @brief This method has been reimplemented. It paints the whole table. * * @param[in] event Paint event * * @return Nothing. */ void AbstractTableView::paintEvent(QPaintEvent* event) { if(!mAllowPainting) return; if(getColumnCount()) //make sure the last column is never smaller than the window { int totalWidth = 0; for(int i = 0; i < getColumnCount(); i++) totalWidth += getColumnWidth(i); int lastWidth = 0; for(int i = 0; i < getColumnCount() - 1; i++) lastWidth += getColumnWidth(i); int width = this->viewport()->width(); lastWidth = width > lastWidth ? width - lastWidth : 0; int last = getColumnCount() - 1; if(totalWidth < width) setColumnWidth(last, lastWidth); else setColumnWidth(last, getColumnWidth(last)); } Q_UNUSED(event); QPainter wPainter(this->viewport()); int wViewableRowsCount = getViewableRowsCount(); int scrollValue = -horizontalScrollBar()->value(); int x = scrollValue; int y = 0; // Reload data if needed if(mPrevTableOffset != mTableOffset || mShouldReload == true) { prepareData(); mPrevTableOffset = mTableOffset; mShouldReload = false; } // Paints background wPainter.fillRect(wPainter.viewport(), QBrush(backgroundColor)); // Paints header if(mHeader.isVisible == true) { for(int i = 0; i < getColumnCount(); i++) { QStyleOptionButton wOpt; if((mColumnList[i].header.isPressed == true) && (mColumnList[i].header.isMouseOver == true)) wOpt.state = QStyle::State_Sunken; else wOpt.state = QStyle::State_Enabled; wOpt.rect = QRect(x, y, getColumnWidth(i), getHeaderHeight()); mHeaderButtonSytle.style()->drawControl(QStyle::CE_PushButton, &wOpt, &wPainter, &mHeaderButtonSytle); wPainter.setPen(headerTextColor); wPainter.drawText(QRect(x + 4, y, getColumnWidth(i) - 8, getHeaderHeight()), Qt::AlignVCenter | Qt::AlignLeft, mColumnList[i].title); x += getColumnWidth(i); } } x = scrollValue; y = getHeaderHeight(); // Iterate over all columns and cells for(int j = 0; j < getColumnCount(); j++) { for(int i = 0; i < wViewableRowsCount; i++) { // Paints cell contents if(i < mNbrOfLineToPrint) { // Don't draw cells if the flag is set, and no process is running //if(!mDrawDebugOnly || DbgIsDebugging()) if(true) { QString wStr = paintContent(&wPainter, mTableOffset, i, j, x, y, getColumnWidth(j), getRowHeight()); if(wStr.length()) { wPainter.setPen(textColor); wPainter.drawText(QRect(x + 4, y, getColumnWidth(j) - 4, getRowHeight()), Qt::AlignVCenter | Qt::AlignLeft, wStr); } } } // Paints cell right borders wPainter.setPen(separatorColor); wPainter.drawLine(x + getColumnWidth(j) - 1, y, x + getColumnWidth(j) - 1, y + getRowHeight() - 1); // Update y for the next iteration y += getRowHeight(); } y = getHeaderHeight(); x += getColumnWidth(j); } //emit repainted(); }
void SortingCompetition::algorithmTester(void){ int A = 1; int stepSize = 10000; int max = 10001; //number of sorting methods implemented int sortingCount = 1; //setting number of words in RandomInput.txt this->inputSize = A*stepSize; //output header to file for output ofstream output("SortingAnalysis.txt"); output<<"N,"; for(int y = 0;y<sortingCount;y++){ switch(y){ case 0: output<<"Bubble Sort,"; case 1: output<<"Merge Sort,"; } } output<<endl; //close output file temporarily while make the randomInput file output.close(); while(A*stepSize<max){ //function call to make random input file from the words collected from input.txt makeRandomFile(A*stepSize,"RandomInput.txt"); //processing now done on setFileName("RandomInput.txt"); //prepare words2 with RandomInput file instead readRandomData(stepSize); prepareData(); //re-open output file and append to the end output.open("SortingAnalysis.txt",std::ios_base::app); //output input size to output file cout<<A*stepSize<<", "; //find average of all sorting methods for this specific //input size for(int i = 0;i<sortingCount;i++){ double sumRuntime = 0; for(int j = 0;j<30;j++){ //declare 2 time points std::chrono::time_point<std::chrono::system_clock> start, end; //store current time (now()) in start start = std::chrono::system_clock::now(); //decide which sorting method to use switch(i){ case 0: bubbleSort(); case 1: mergeSort(0,getWordCount()-1); } //store time(now()) in end end = std::chrono::system_clock::now(); //get No. of seconds elapsed & output duration //need to do this multiple times & get average std::chrono::duration<double> elapsed_seconds = end-start; sumRuntime += elapsed_seconds.count(); }//end of 30 runtimes //find average runtime double average = sumRuntime/30; //output to file the average run time and size cout<<fixed<<setprecision(9)<<average<<", "; }//processed all sorting algorithms //increment input size A +=1; this->inputSize = A*stepSize; cout<<endl; } }
int main() { // check that we are running on Galileo or Edison mraa_platform_t platform = mraa_get_platform_type(); if ((platform != MRAA_INTEL_GALILEO_GEN1) && (platform != MRAA_INTEL_GALILEO_GEN2) && (platform != MRAA_INTEL_EDISON_FAB_C)) { std::cerr << "Unsupported platform, exiting" << std::endl; return MRAA_ERROR_INVALID_PLATFORM; } // temperature sensor connected to A0 (analog in) upm::GroveTemp* temp_sensor = new upm::GroveTemp(0); // LCD connected to the default I2C bus upm::Jhd1313m1* lcd = new upm::Jhd1313m1(0); std::stringstream row_1, row_2; upm::GroveRelay* relay = new upm::GroveRelay(4); // simple error checking if ((temp_sensor == NULL) || (lcd == NULL) || (relay == NULL)) { std::cerr << "Can't create all objects, exiting" << std::endl; return MRAA_ERROR_UNSPECIFIED; } // loop forever updating the temperature values every second for (;;) { float temperature = MySensors::load_temperature(0); float humidity = MySensors::load_humidity(1); row_1.str(std::string()); row_2.str(std::string()); row_2 << "Temperature " << std::fixed << std::setprecision(2) <<temperature << "Cº"; row_1 << "Humidity "<< std::fixed << std::setprecision(0) << humidity << "\%"; //write in the LCD lcd->setCursor(0,0); lcd->write(row_1.str()); lcd->setCursor(1,0); lcd->write(row_2.str()); //clear LCD row_1.str(std::string()); row_2.str(std::string()); Check_pump_status(humidity,relay); //Prepare data to upload to Fi-Ware FiWareConnector::Table measures = prepareData(humidity,temperature,relay->isOn()); //Upload data to Fi-Ware FiWareConnector::post_measures(measures); sleep(20); } return MRAA_SUCCESS; }
void Z3DPunctaFilter::process(Z3DEye) { if (m_dataIsInvalid) { prepareData(); } }
void SkyboxModel::Init() { prepareData(); Setup(); }
int CQboduinoDriver::write(cereal::CerealPort *ser, std::string& escritura) { std::string serialData; prepareData(escritura, serialData); return ser->write(serialData.c_str(),serialData.size()); }
std::unique_lock<std::mutex> getLock() { std::unique_lock<std::mutex> lk(some_mutex); prepareData(); return lk; }
RTroubleCodeItem::RTroubleCodeItem(const dnt::RTroubleCodeItemPtr &native) : _native(native) { prepareData(); }
void Ivy::birth() { //evolve a gaussian filter over the adhesian vectors float gaussian[11] = {1.0f, 2.0f, 4.0f, 7.0f, 9.0f, 10.0f, 9.0f, 7.0f, 4.0f, 2.0f, 1.0f }; for(unsigned int r=0; r < roots.size(); r++) { for(int g = 0; g <5; ++g) { IvyRoot root = roots[r]; for(unsigned int n=0; n < root.nodes.size(); n++) { Vector3d e; for (int i = -5; i <= 5; ++i) { Vector3d tmpAdhesion; if ((n + i) < 0) tmpAdhesion = root.nodes.front().adhesionVector; if ((n + i) >= root.nodes.size()) tmpAdhesion = root.nodes.back().adhesionVector; if (((n + i) >= 0) && ((n + i) < root.nodes.size())) tmpAdhesion = root.nodes[n + i].adhesionVector; e += tmpAdhesion * gaussian[i+5]; } root.nodes[n].smoothAdhesionVector = e / 56.0f; } for(unsigned int n=0; n < root.nodes.size(); n++) { root.nodes[n].adhesionVector = root.nodes[n].smoothAdhesionVector; } } } // for (std::vector<IvyRoot>::iterator root = roots.begin(); root != roots.end(); ++root) // { // for (int g = 0; g < 5; ++g) // { // for (std::vector<IvyNode>::iterator node = root->nodes.begin(); node != root->nodes.end(); ++node) // { // Vector3d e; // for (int i = -5; i <= 5; ++i) // { // Vector3d tmpAdhesion; // if ((node + i) < root->nodes.begin()) // tmpAdhesion = root->nodes.front().adhesionVector; // if ((node + i) >= root->nodes.end()) // tmpAdhesion = root->nodes.back().adhesionVector; // if (((node + i) >= root->nodes.begin()) && ((node + i) < root->nodes.end())) // tmpAdhesion = (node + i)->adhesionVector; // e += tmpAdhesion * gaussian[i+5]; // } // node->smoothAdhesionVector = e / 56.0f; // } // for (std::vector<IvyNode>::iterator node = root->nodes.begin(); node != root->nodes.end(); ++node) // { // node->adhesionVector = node->smoothAdhesionVector; // } // } // } //parameters that depend on the scene object bounding sphere float local_ivyLeafSize = Common::mesh.boundingSphereRadius * ivySize * ivyLeafSize; float local_ivyBranchSize = Common::mesh.boundingSphereRadius * ivySize * ivyBranchSize; //reset existing geometry BasicMesh::reset(); //set data path path = "../textures/"; //create material for leafs BasicMaterial tmpMaterial; tmpMaterial.id = 1; tmpMaterial.name = "leaf_adult"; tmpMaterial.texFile = "efeu1.png"; materials.push_back( tmpMaterial ); //create second material for leafs tmpMaterial.id = 2; tmpMaterial.name = "leaf_young"; tmpMaterial.texFile = "efeu0.png"; materials.push_back( tmpMaterial ); //create material for branches tmpMaterial.id = 3; tmpMaterial.name = "branch"; tmpMaterial.texFile = "efeu_branch.png"; materials.push_back( tmpMaterial ); //create leafs for (std::vector<IvyRoot>::iterator root = roots.begin(); root != roots.end(); ++root) { //simple multiplier, just to make it a more dense for (int i = 0; i < 10; ++i) { //srand(i + (root - roots.begin()) * 10); for (std::vector<IvyNode>::iterator node = root->nodes.begin(); node != root->nodes.end(); ++node) { //weight depending on ratio of node length to total length float weight = pow(node->length / root->nodes.back().length, 0.7f); //test: the probability of leaves on the ground is increased float groundIvy = std::max<float>(0.0f, -Vector3d::dotProduct( Vector3d(0.0f, 1.0f, 0.0f), Vector3d::getNormalized(node->adhesionVector) )); weight += groundIvy * pow(1.0f - node->length / root->nodes.back().length, 2.0f); //random influence float probability = rand()/(float)RAND_MAX; if (probability * weight > leafProbability) { //alignment weight depends on the adhesion "strength" float alignmentWeight = node->adhesionVector.length(); //horizontal angle (+ an epsilon vector, otherwise there's a problem at 0� and 90�... mmmh) float phi = Vector2d::vectorToPolar( Vector2d::getNormalized( Vector2d(node->adhesionVector.z, node->adhesionVector.x) ) + Vector2d::getEpsilon() ) - PI * 0.5f; //vertical angle, trimmed by 0.5 float theta = Vector3d::getAngle( node->adhesionVector, Vector3d(0.0f, -1.0f, 0.0f) ) * 0.5f; //center of leaf quad Vector3d center = node->pos + Vector3d::getRandomized() * local_ivyLeafSize; //size of leaf float sizeWeight = 1.5f - (cos(weight * 2.0f * PI) * 0.5f + 0.5f); //random influence phi += (rand()/(float)RAND_MAX - 0.5f) * (1.3f - alignmentWeight); theta += (rand()/(float)RAND_MAX - 0.5f) * (1.1f - alignmentWeight); //create vertices BasicVertex tmpVertex; tmpVertex.pos = center + Vector3d(-local_ivyLeafSize * sizeWeight, 0.0f, local_ivyLeafSize * sizeWeight); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 0.0f, 1.0f), theta); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 1.0f, 0.0f), phi); tmpVertex.pos += Vector3d::getRandomized() * local_ivyLeafSize * sizeWeight * 0.5f; vertices.push_back( tmpVertex ); tmpVertex.pos = center + Vector3d( local_ivyLeafSize * sizeWeight, 0.0f, local_ivyLeafSize * sizeWeight); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 0.0f, 1.0f), theta); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 1.0f, 0.0f), phi); tmpVertex.pos += Vector3d::getRandomized() * local_ivyLeafSize * sizeWeight * 0.5f; vertices.push_back( tmpVertex ); tmpVertex.pos = center + Vector3d(-local_ivyLeafSize * sizeWeight, 0.0f, -local_ivyLeafSize * sizeWeight); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 0.0f, 1.0f), theta); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 1.0f, 0.0f), phi); tmpVertex.pos += Vector3d::getRandomized() * local_ivyLeafSize * sizeWeight * 0.5f; vertices.push_back( tmpVertex ); tmpVertex.pos = center + Vector3d( local_ivyLeafSize * sizeWeight, 0.0f, -local_ivyLeafSize * sizeWeight); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 0.0f, 1.0f), theta); tmpVertex.pos = Vector3d::rotateAroundAxis(tmpVertex.pos, center, Vector3d(0.0f, 1.0f, 0.0f), phi); tmpVertex.pos += Vector3d::getRandomized() * local_ivyLeafSize * sizeWeight * 0.5f; vertices.push_back( tmpVertex ); //create texCoords BasicTexCoord tmpTexCoord; tmpTexCoord.pos = Vector2d( 0.0f, 1.0f); texCoords.push_back( tmpTexCoord ); tmpTexCoord.pos = Vector2d( 1.0f, 1.0f); texCoords.push_back( tmpTexCoord ); tmpTexCoord.pos = Vector2d( 0.0f, 0.0f); texCoords.push_back( tmpTexCoord ); tmpTexCoord.pos = Vector2d( 1.0f, 0.0f); texCoords.push_back( tmpTexCoord ); //create triangle BasicTriangle tmpTriangle; tmpTriangle.matid = 1; float probability = rand()/(float)RAND_MAX; if (probability * weight > leafProbability) tmpTriangle.matid = 2; tmpTriangle.v0id = (unsigned int)vertices.size()-1; tmpTriangle.v1id = (unsigned int)vertices.size()-3; tmpTriangle.v2id = (unsigned int)vertices.size()-2; tmpTriangle.t0id = (unsigned int)vertices.size()-1; tmpTriangle.t1id = (unsigned int)vertices.size()-3; tmpTriangle.t2id = (unsigned int)vertices.size()-2; triangles.push_back( tmpTriangle ); tmpTriangle.v0id = (unsigned int)vertices.size()-2; tmpTriangle.v1id = (unsigned int)vertices.size()-0; tmpTriangle.v2id = (unsigned int)vertices.size()-1; tmpTriangle.t0id = (unsigned int)vertices.size()-2; tmpTriangle.t1id = (unsigned int)vertices.size()-0; tmpTriangle.t2id = (unsigned int)vertices.size()-1; triangles.push_back( tmpTriangle ); } } } } //branches for (std::vector<IvyRoot>::iterator root = roots.begin(); root != roots.end(); ++root) { //process only roots with more than one node if (root->nodes.size() == 1) continue; //branch diameter depends on number of parents float local_ivyBranchDiameter = 1.0f / (float)(root->parents + 1) + 1.0f; for (std::vector<IvyNode>::iterator node = root->nodes.begin(); node != root->nodes.end()-1; ++node) { //weight depending on ratio of node length to total length float weight = node->length / root->nodes.back().length; //create trihedral vertices Vector3d up = Vector3d(0.0f, -1.0f, 0.0f); Vector3d basis = Vector3d::getNormalized((node + 1)->pos - node->pos); Vector3d b0 = Vector3d::getNormalized( Vector3d::crossProduct(up, basis) ) * local_ivyBranchDiameter * local_ivyBranchSize * (1.3f - weight) + node->pos; Vector3d b1 = Vector3d::rotateAroundAxis(b0, node->pos, basis, 2.09f); Vector3d b2 = Vector3d::rotateAroundAxis(b0, node->pos, basis, 4.18f); //create vertices BasicVertex tmpVertex; tmpVertex.pos = b0; vertices.push_back( tmpVertex ); tmpVertex.pos = b1; vertices.push_back( tmpVertex ); tmpVertex.pos = b2; vertices.push_back( tmpVertex ); //create texCoords BasicTexCoord tmpTexCoord; float texV = (node - root->nodes.begin()) % 2 == 0 ? 1.0f : 0.0f; tmpTexCoord.pos = Vector2d( 0.0f, texV); texCoords.push_back( tmpTexCoord ); tmpTexCoord.pos = Vector2d( 0.3f, texV); texCoords.push_back( tmpTexCoord ); tmpTexCoord.pos = Vector2d( 0.6f, texV); texCoords.push_back( tmpTexCoord ); if (node == root->nodes.begin()) continue; //create triangle BasicTriangle tmpTriangle; tmpTriangle.matid = 3; tmpTriangle.v0id = (unsigned int)vertices.size()-3; tmpTriangle.v1id = (unsigned int)vertices.size()-0; tmpTriangle.v2id = (unsigned int)vertices.size()-4; tmpTriangle.t0id = (unsigned int)vertices.size()-3; tmpTriangle.t1id = (unsigned int)vertices.size()-0; tmpTriangle.t2id = (unsigned int)vertices.size()-4; triangles.push_back( tmpTriangle ); tmpTriangle.v0id = (unsigned int)vertices.size()-4; tmpTriangle.v1id = (unsigned int)vertices.size()-0; tmpTriangle.v2id = (unsigned int)vertices.size()-1; tmpTriangle.t0id = (unsigned int)vertices.size()-4; tmpTriangle.t1id = (unsigned int)vertices.size()-0; tmpTriangle.t2id = (unsigned int)vertices.size()-1; triangles.push_back( tmpTriangle ); tmpTriangle.v0id = (unsigned int)vertices.size()-4; tmpTriangle.v1id = (unsigned int)vertices.size()-1; tmpTriangle.v2id = (unsigned int)vertices.size()-5; tmpTriangle.t0id = (unsigned int)vertices.size()-4; tmpTriangle.t1id = (unsigned int)vertices.size()-1; tmpTriangle.t2id = (unsigned int)vertices.size()-5; triangles.push_back( tmpTriangle ); tmpTriangle.v0id = (unsigned int)vertices.size()-5; tmpTriangle.v1id = (unsigned int)vertices.size()-1; tmpTriangle.v2id = (unsigned int)vertices.size()-2; tmpTriangle.t0id = (unsigned int)vertices.size()-5; tmpTriangle.t1id = (unsigned int)vertices.size()-1; tmpTriangle.t2id = (unsigned int)vertices.size()-2; triangles.push_back( tmpTriangle ); tmpTriangle.v0id = (unsigned int)vertices.size()-5; tmpTriangle.v1id = (unsigned int)vertices.size()-2; tmpTriangle.v2id = (unsigned int)vertices.size()-0; tmpTriangle.t0id = (unsigned int)vertices.size()-5; tmpTriangle.t1id = (unsigned int)vertices.size()-2; tmpTriangle.t2id = (unsigned int)vertices.size()-0; triangles.push_back( tmpTriangle ); tmpTriangle.v0id = (unsigned int)vertices.size()-5; tmpTriangle.v1id = (unsigned int)vertices.size()-0; tmpTriangle.v2id = (unsigned int)vertices.size()-3; tmpTriangle.t0id = (unsigned int)vertices.size()-5; tmpTriangle.t1id = (unsigned int)vertices.size()-0; tmpTriangle.t2id = (unsigned int)vertices.size()-3; triangles.push_back( tmpTriangle ); } } //initialize ivy mesh loadTextures(); prepareData(); calculateVertexNormals(); prepareData(); createDisplayList(true); }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void AmplitudeProcessor::process(const Record *record) { // Sampling frequency has not been set yet if ( _stream.fsamp == 0.0 ) return; int n = (int)_data.size(); // signal and noise window relative to _continuous->startTime() double dt0 = _trigger - dataTimeWindow().startTime(); double dt1 = dataTimeWindow().endTime() - dataTimeWindow().startTime(); double dtw1 = timeWindow().endTime() - dataTimeWindow().startTime(); double dtn1 = dt0 + _config.noiseBegin; double dtn2 = dt0 + _config.noiseEnd; double dts1 = dt0 + _config.signalBegin; double dts2 = dt0 + _config.signalEnd; // Noise indicies int ni1 = int(dtn1*_stream.fsamp+0.5); int ni2 = int(dtn2*_stream.fsamp+0.5); if ( ni1 < 0 || ni2 < 0 ) { SEISCOMP_DEBUG("Noise data not available -> abort"); setStatus(Error, 1); return; } if ( n < ni2 ) { // the noise window is not complete return; } // **** compute signal amplitude ******************************** // these are the offsets of the beginning and end // of the signal window relative to the start of // the continuous record in samples int i1 = int(dts1*_stream.fsamp+0.5); int i2 = int(dts2*_stream.fsamp+0.5); //int progress = int(100.*(n-i1)/(i2-i1)); //int progress = int(100.*(dt1-dts1)/(dts2-dts1)); int progress = int(100.*(dt1-dts1)/(std::max(dtw1,dts2)-dts1)); if ( progress > 100 ) progress = 100; setStatus(InProgress, progress); if ( i1 < 0 ) i1 = 0; if ( i2 > n ) i2 = n; bool unlockCalculation = ((_enableUpdates && !_enableResponses) && progress > 0) || progress >= 100; if ( unlockCalculation ) { if ( _streamConfig[_usedComponent].gain == 0.0 ) { setStatus(MissingGain, 0); return; } // **** prepare the data to compute the noise prepareData(_data); if ( isFinished() ) return; // **** compute noise amplitude ********************************* // if the noise hasn't been measured yet... if ( !_noiseAmplitude ) { // compute pre-arrival data offset and noise amplitude double off = 0., amp = 0.; if ( !computeNoise(_data, ni1, ni2, &off, &) ) { SEISCOMP_DEBUG("Noise computation failed -> abort"); setStatus(Error, 2); return; } _noiseOffset = off; _noiseAmplitude = amp; } AmplitudeIndex index; Result res; res.component = _usedComponent; res.record = record; res.period = -1; res.snr = -1; res.amplitude.value = -1; res.amplitude.lowerUncertainty = Core::None; res.amplitude.upperUncertainty = Core::None; index.index = -1; index.begin = 0; index.end = 0; double dtsw1, dtsw2; if ( _searchBegin ) { dtsw1 = dt0 + *_searchBegin; if ( dtsw1 < dts1 ) dtsw1 = dts1; if ( dtsw1 > dts2 ) dtsw1 = dts2; } else dtsw1 = dts1; if ( _searchEnd ) { dtsw2 = dt0 + *_searchEnd; if ( dtsw2 < dts1 ) dtsw2 = dts1; if ( dtsw2 > dts2 ) dtsw2 = dts2; } else dtsw2 = dts2; int si1 = int(dtsw1*_stream.fsamp+0.5); int si2 = int(dtsw2*_stream.fsamp+0.5); si1 = std::max(si1, i1); si2 = std::min(si2, i2); if ( !computeAmplitude(_data, i1, i2, si1, si2, *_noiseOffset, &index, &res.amplitude, &res.period, &res.snr) ) { if ( progress >= 100 ) { if ( status() == LowSNR ) SEISCOMP_DEBUG("Amplitude %s computation for stream %s failed because of low SNR (%.2f < %.2f)", _type.c_str(), record->streamID().c_str(), res.snr, _config.snrMin); else { SEISCOMP_DEBUG("Amplitude %s computation for stream %s failed -> abort", _type.c_str(), record->streamID().c_str()); setStatus(Error, 3); } _lastAmplitude = Core::None; } return; } if ( _lastAmplitude ) { if ( res.amplitude.value <= *_lastAmplitude ) { if ( progress >= 100 ) { setStatus(Finished, 100.); _lastAmplitude = Core::None; } return; } } _lastAmplitude = res.amplitude.value; double dt = index.index / _stream.fsamp; res.period /= _stream.fsamp; if ( index.begin > index.end ) std::swap(index.begin, index.end); // Update status information res.time.reference = dataTimeWindow().startTime() + Core::TimeSpan(dt); //res.time.begin = index.begin / _stream.fsamp; //res.time.end = index.end / _stream.fsamp; res.time.begin = (si1 - index.index) / _stream.fsamp; res.time.end = (si2 - index.index) / _stream.fsamp; if ( progress >= 100 ) { setStatus(Finished, 100.); _lastAmplitude = Core::None; } emitAmplitude(res); } }
int CQboduinoDriver::write(cereal::CerealPort *port, std::string& toWrite) { std::string serialData; prepareData(toWrite, serialData); return port->write(serialData.c_str(),serialData.size()); }