// private helper methods bool SceneGraphNode::sphereInsideFrustum(const psc& s_pos, const PowerScaledScalar& s_rad, const Camera* camera) { // direction the camera is looking at in power scale psc psc_camdir = psc(glm::vec3(camera->viewDirectionWorldSpace())); // the position of the camera, moved backwards in the view direction to encapsulate // the sphere radius psc U = camera->position() - psc_camdir * s_rad * (1.0 / camera->sinMaxFov()); // the vector to the object from the new position psc D = s_pos - U; const double a = psc_camdir.angle(D); if (a < camera->maxFov()) { // center is inside K'' D = s_pos - camera->position(); if (D.length() * psc_camdir.length() * camera->sinMaxFov() <= -psc_camdir.dot(D)) { // center is inside K'' and inside K' return D.length() <= s_rad; } else { // center is inside K'' and outside K' return true; } } else { // outside the maximum angle return false; } }
void InteractionHandler::update(double deltaTime) { _deltaTime = deltaTime; _mouseController->update(deltaTime); bool hasKeys = false; psc pos; glm::quat q; _keyframeMutex.lock(); if (_keyframes.size() > 4){ //wait until enough samples are buffered hasKeys = true; openspace::network::datamessagestructures::PositionKeyframe p0, p1, p2, p3; p0 = _keyframes[0]; p1 = _keyframes[1]; p2 = _keyframes[2]; p3 = _keyframes[3]; //interval check if (_currentKeyframeTime < p1._timeStamp){ _currentKeyframeTime = p1._timeStamp; } double t0 = p1._timeStamp; double t1 = p2._timeStamp; double fact = (_currentKeyframeTime - t0) / (t1 - t0); //glm::dvec4 v = positionInterpCR.interpolate(fact, _keyframes[0]._position.dvec4(), _keyframes[1]._position.dvec4(), _keyframes[2]._position.dvec4(), _keyframes[3]._position.dvec4()); glm::dvec4 v = ghoul::interpolateLinear(fact, p1._position.dvec4(), p2._position.dvec4()); pos = psc(v.x, v.y, v.z, v.w); q = ghoul::interpolateLinear(fact, p1._viewRotationQuat, p2._viewRotationQuat); //we're done with this sample interval if (_currentKeyframeTime >= p2._timeStamp){ _keyframes.erase(_keyframes.begin()); _currentKeyframeTime = p1._timeStamp; } _currentKeyframeTime += deltaTime; } _keyframeMutex.unlock(); if (hasKeys) { _camera->setPosition(pos); _camera->setRotation(q); } }
Eigen::MatrixXf powerspectrum::from_pcm(const Eigen::VectorXf& pcm_samples) { MINILOG(logTRACE) << "Powerspectrum computation. input samples=" << pcm_samples.size(); // check if inputs are sane if ((pcm_samples.size() < win_size) || (hop_size > win_size)) { return Eigen::MatrixXf(0, 0); } size_t frames = (pcm_samples.size() - (win_size-hop_size)) / hop_size; size_t freq_bins = win_size/2 + 1; // initialize power spectrum Eigen::MatrixXf ps(freq_bins, frames); // peak normalization value float pcm_scale = std::max(fabs(pcm_samples.minCoeff()), fabs(pcm_samples.maxCoeff())); // scale signal to 96db (16bit) pcm_scale = std::pow(10.0f, 96.0f/20.0f) / pcm_scale; // compute the power spectrum for (size_t i = 0; i < frames; i++) { // fill pcm for (int j = 0; j < win_size; j++) { kiss_pcm[j] = pcm_samples(i*hop_size+j) * pcm_scale * win_funct(j); } // fft kiss_fftr(kiss_status, kiss_pcm, kiss_freq); // save powerspectrum frame Eigen::MatrixXf::ColXpr psc(ps.col(i)); for (int j = 0; j < win_size/2+1; j++) { psc(j) = std::pow(kiss_freq[j].r, 2) + std::pow(kiss_freq[j].i, 2); } } MINILOG(logTRACE) << "Powerspectrum finished. size=" << ps.rows() << "x" << ps.cols(); return ps; }
void PeerStateList::addPeer(PeerState ps) { PeerStateContainer psc(ps); auto timer = std::make_unique<boost::asio::deadline_timer>(m_context.ios, boost::posix_time::time_duration(0, 20, 0)); timer->async_wait(boost::bind(&PeerStateList::timerCallback, this, boost::asio::placeholders::error, ps.getHash())); psc.timer = std::move(timer); auto itr = m_container.get<1>().find(ps.getHash()); if(itr == m_container.get<1>().end()) m_container.insert(std::move(psc)); else m_container.get<1>().replace(itr, std::move(psc)); }
void InteractionHandler::distanceDelta(const PowerScaledScalar& distance, size_t iterations) { if (iterations > 5) return; //assert(this_); lockControls(); psc relative = _camera->position(); const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc(); unlockControls(); psc relative_origin_coordinate = relative - origin; const glm::vec3 dir(relative_origin_coordinate.direction()); glm::vec3 newdir = dir * distance[0]; relative_origin_coordinate = newdir; relative_origin_coordinate[3] = distance[1]; relative = relative + relative_origin_coordinate; relative_origin_coordinate = relative - origin; if (relative_origin_coordinate.vec4().x == 0.f && relative_origin_coordinate.vec4().y == 0.f && relative_origin_coordinate.vec4().z == 0.f) // TODO: this shouldn't be allowed to happen; a mechanism to prevent the camera to coincide with the origin is necessary (ab) return; newdir = relative_origin_coordinate.direction(); // update only if on the same side of the origin if (glm::angle(newdir, dir) < 90.0f) { _camera->setPosition(relative); } else { PowerScaledScalar d2 = distance; d2[0] *= 0.75f; d2[1] *= 0.85f; distanceDelta(d2, iterations + 1); } }
/// TODO void Gist::on_canvas_statusChanged(VisualNode* n, const Statistics& stats, bool finished) { nodeStatInspector->node(execution->getNA(),n,stats,finished); /// for single node stats if (!finished) { showNodeStats->setEnabled(false); // stop-> setEnabled(true); // reset->setEnabled(false); navNextSol->setEnabled(false); navPrevSol->setEnabled(false); // searchNext->setEnabled(false); // searchAll->setEnabled(false); toggleHidden->setEnabled(false); hideFailed->setEnabled(false); // hideSize->setEnabled(false); // labelBranches->setEnabled(false); // labelPath->setEnabled(false); // toggleStop->setEnabled(false); // unstopAll->setEnabled(false); center->setEnabled(false); /// ?? exportPDF->setEnabled(false); exportWholeTreePDF->setEnabled(false); print->setEnabled(false); // printSearchLog->setEnabled(false); bookmarkNode->setEnabled(false); bookmarksGroup->setEnabled(false); } else { // stop->setEnabled(false); // reset->setEnabled(true); if ( (n->isOpen() || n->hasOpenChildren()) && (!n->isHidden()) ) { // searchNext->setEnabled(true); // searchAll->setEnabled(true); } else { // searchNext->setEnabled(false); // searchAll->setEnabled(false); } if (n->getNumberOfChildren() > 0) { toggleHidden->setEnabled(true); hideFailed->setEnabled(true); // hideSize->setEnabled(true); // unstopAll->setEnabled(true); } else { toggleHidden->setEnabled(false); hideFailed->setEnabled(false); // hideSize->setEnabled(false); // unhideAll->setEnabled(false); // unstopAll->setEnabled(false); } toggleStop->setEnabled(n->getStatus() == STOP || n->getStatus() == UNSTOP); showNodeStats->setEnabled(true); labelPath->setEnabled(true); VisualNode* root = n; while (!root->isRoot()) { root = root->getParent(execution->getNA()); } NextSolCursor nsc(n, false, execution->getNA()); PreorderNodeVisitor<NextSolCursor> nsv(nsc); nsv.run(); navNextSol->setEnabled(nsv.getCursor().node() != root); NextSolCursor psc(n, true, execution->getNA()); PreorderNodeVisitor<NextSolCursor> psv(psc); psv.run(); navPrevSol->setEnabled(psv.getCursor().node() != root); center->setEnabled(true); exportPDF->setEnabled(true); exportWholeTreePDF->setEnabled(true); print->setEnabled(true); printSearchLog->setEnabled(true); bookmarkNode->setEnabled(true); bookmarksGroup->setEnabled(true); } emit statusChanged(stats,finished); }
void Unreal3DExport::WriteScript() { // Write script file { fScript = _tfopen(ScriptFileName,_T("wb")); if( !fScript ) { ProgressMsg.printf(GetString(IDS_ERR_FSCRIPT),ScriptFileName); throw MAXException(ProgressMsg.data()); } TSTR buf; // Write class def _ftprintf( fScript, _T("class %s extends Object;\n\n"), FileName ); // write import _ftprintf( fScript, _T("#exec MESH IMPORT MESH=%s ANIVFILE=%s_a.3D DATAFILE=%s_d.3D \n"), FileName, FileName, FileName ); // write origin & rotation // TODO: figure out why it's incorrect without -1 Point3 porg = OptOffset * OptScale * -1; _ftprintf( fScript, _T("#exec MESH ORIGIN MESH=%s X=%f Y=%f Z=%f PITCH=%d YAW=%d ROLL=%d \n"), FileName, porg.x, porg.y, porg.z, (int)OptRot.x, (int)OptRot.y, (int)OptRot.z ); // write mesh scale Point3 psc( Point3(1.0f/OptScale.x,1.0f/OptScale.y,1.0f/OptScale.z)); _ftprintf( fScript, _T("#exec MESH SCALE MESH=%s X=%f Y=%f Z=%f \n"), FileName, psc.x, psc.y, psc.z ); // write meshmap _ftprintf( fScript, _T("#exec MESHMAP NEW MESHMA=P%s MESH=%smap \n"), FileName, FileName ); // write meshmap scale _ftprintf( fScript, _T("#exec MESHMAP SCALE MESHMAP=%s X=%f Y=%f Z=%f \n"), FileName, psc.x, psc.y, psc.z ); // write sequence _ftprintf( fScript, _T("#exec MESH SEQUENCE MESH=%s SEQ=%s STARTFRAME=%d NUMFRAMES=%d \n"), FileName, _T("All"), 0, FrameCount-1 ); // Get World NoteTrack ReferenceTarget *rtscene = pInt->GetScenePointer(); for( int t=0; t<rtscene->NumNoteTracks(); ++t ) { DefNoteTrack* notetrack = static_cast<DefNoteTrack*>(rtscene->GetNoteTrack(t)); for( int k=0; k<notetrack->keys.Count(); ++k ) { NoteKey* notekey = notetrack->keys[k]; TSTR text = notekey->note; int notetime = notekey->time / pScene->GetSceneTicks(); while( !text.isNull() ) { TSTR cmd = SplitStr(text,_T('\n')); if( MatchPattern(cmd,TSTR(_T("a *")),TRUE) ) { SplitStr(cmd,_T(' ')); TSTR seq = SplitStr(cmd,_T(' ')); int end = _ttoi(SplitStr(cmd,_T(' ')));; TSTR rate = SplitStr(cmd,_T(' ')); TSTR group = SplitStr(cmd,_T(' ')); if( seq.isNull() ) { ProgressMsg.printf(_T("Missing animation name in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } if( end <= notetime ) { ProgressMsg.printf(_T("Invalid animation endframe (%d) in notekey #%d"),end,notetime); throw MAXException(ProgressMsg.data()); } int startframe = notetime; int numframes = end - notetime; buf.printf( _T("#exec MESH SEQUENCE MESH=%s SEQ=%s STARTFRAME=%d NUMFRAMES=%d"), FileName, seq, notetime, numframes ); if( !rate.isNull() ) buf.printf( _T("%s RATE=%f"), buf, rate ); if( !group.isNull() ) buf.printf( _T("%s GROUP=%f"), buf, rate ); SeqName = seq; SeqFrame = startframe; buf.printf( _T("%s \n"), buf ); _fputts( buf, fScript ); } else if( MatchPattern(cmd,TSTR(_T("n *")),TRUE) ) { SplitStr(cmd,_T(' ')); TSTR func = SplitStr(cmd,_T(' ')); TSTR time = SplitStr(cmd,_T(' ')); if( func.isNull() ) { ProgressMsg.printf(_T("Missing notify name in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } if( time.isNull() ) { ProgressMsg.printf(_T("Missing notify time in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } buf.printf( _T("#exec MESH NOTIFY MESH=%s SEQ=%s TIME=%s FUNCTION=%s"), FileName, SeqName, time, func ); _fputts( buf, fScript ); } } } } // TODO: write materials if( Materials.Count() > 0 ) { for( int i=0; i<Materials.Count(); ++i ) { IGameMaterial* mat = Materials[i].Mat; if( mat == NULL ) continue; _ftprintf( fScript, _T("#exec MESHMAP SETTEXTURE MESHMAP=%s NUM=%d TEXTURE=%s \n"), FileName, i, _T("DefaultTexture") ); } } } }
void Propagation::Propagate(Particle &curr_particle, std::vector<Particle> &ParticleAtMatrix, std::vector<Particle> &ParticleAtGround, bool dropParticlesBelowEnergyThreshold ) const { double theta_deflBF = 0.0; double BNorm = magneticFieldStrength; double zin = curr_particle.Getz(); double Ein = curr_particle.GetEnergy(); int type = curr_particle.GetType(); int wi_last = curr_particle.GetWeigth(); double z_curr = zin; double Ecurr = Ein; bool interacted = 0; double min_dist = 1e12; double walkdone = 0; double E1 = 0; double E2 = 0; double E3 = 0; double stepsize = 0; double Elast = 0; double R = Uniform(0.0, 1.0); double R2 = Uniform(0.0, 1.0); Process proc; proc.SetIncidentParticle(curr_particle); proc.SetBackground(Bkg); double Ethr2 = std::max(fEthr, std::max(ElectronMass,ElectronMass*ElectronMass/proc.feps_sup)); if (Ecurr < Ethr2) { if (!dropParticlesBelowEnergyThreshold) ParticleAtGround.push_back(curr_particle); return; } std::vector<double> EtargetAll = GetEtarget(proc, curr_particle); min_dist = ExtractMinDist(proc, curr_particle.GetType(), R, R2, EtargetAll); interacted = 0; double dz = 0; double zpos = zin; double corrB_factor = 0; double realpath = 0; double min_dist_last = min_dist; while (!interacted) { proc.SetInteractionAngle(cPI); theta_deflBF = 0; realpath = 0.1 * min_dist; theta_deflBF = GetMeanThetaBFDeflection(BNorm, curr_particle.GetEnergy(), curr_particle.GetType(), min_dist); corrB_factor = cos(theta_deflBF); stepsize = realpath * corrB_factor; dz = Mpc2z(stepsize); if ((walkdone + realpath) > min_dist) { interacted = 1; } if (zpos - dz <= 0) { dz = zpos; stepsize = z2Mpc(dz); realpath = stepsize / corrB_factor; } zpos -= dz; walkdone += realpath; Elast = Ecurr; if (type == 0 || type == 22) Ecurr = EnergyLoss1D(Ecurr, zpos + Mpc2z(realpath), zpos, 0); else Ecurr = EnergyLoss1D(Ecurr, zpos + Mpc2z(realpath), zpos, BNorm); z_curr = zpos; curr_particle.Setz(z_curr); curr_particle.SetEnergy(Ecurr); if (z_curr <= 0) { ParticleAtGround.push_back(curr_particle); return; } if (Ecurr <= Ethr2) { if (!dropParticlesBelowEnergyThreshold) { ParticleAtGround.push_back(curr_particle); } return; } proc.SetIncidentParticle(curr_particle); proc.SetCMEnergy(); proc.SetLimits(); // std::vector<double> EtargetAll=GetEtarget(proc,curr_particle); min_dist = ExtractMinDist(proc, curr_particle.GetType(), R, R2, EtargetAll); } //end while if (interacted == 1) { if (proc.GetName() == Process::PP) { E1 = ExtractPPSecondariesEnergy(proc); if (E1 == 0 || E1 == Ecurr) std::cerr << "ERROR in PP process: E : " << Ecurr << " " << E1 << " " << std::endl; Particle pp(11, E1, z_curr,curr_particle.Generation()+1); pp.SetWeigth(wi_last); ParticleAtMatrix.push_back(pp); Particle pe(-11, Ecurr - E1, z_curr,curr_particle.Generation()+1); pe.SetWeigth(wi_last); ParticleAtMatrix.push_back(pe); return; } //if PP else if (proc.GetName() == Process::DPP) { E1 = (Ecurr - 2 * ElectronMass) / 2.0; if (E1 == 0) std::cerr << "ERROR in DPP process E : " << E1 << std::endl; Particle pp(11, E1, z_curr,curr_particle.Generation()+1); pp.SetWeigth(wi_last); ParticleAtMatrix.push_back(pp); Particle pe(-11, E1, z_curr,curr_particle.Generation()+1); pe.SetWeigth(wi_last); ParticleAtMatrix.push_back(pe); return; } //end if DPP else if (proc.GetName() == Process::ICS) { E1 = ExtractICSSecondariesEnergy(proc); E2 = Ecurr - E1; if (E1 == 0 || E2 == 0) std::cerr << "ERROR in ICS process E : " << E1 << " " << E2 << std::endl; Particle pp(curr_particle.GetType(), E1, z_curr,curr_particle.Generation()+1); pp.SetWeigth(wi_last); ParticleAtMatrix.push_back(pp); Particle pg(22, E2, z_curr,curr_particle.Generation()+1); pg.SetWeigth(wi_last); ParticleAtMatrix.push_back(pg); return; } //end if ics else if (proc.GetName() == Process::TPP) { E1 = E2 = ExtractTPPSecondariesEnergy(proc); E3 = Ecurr - E1 - E2; if (E1 == 0 || E2 == 0 || E3 == 0) std::cerr << "ERROR in TPP process E : " << E1 << " " << E2 << std::endl; Particle pp(11, E1, z_curr,curr_particle.Generation()+1); pp.SetWeigth(wi_last); ParticleAtMatrix.push_back(pp); Particle pe(-11, E1, z_curr,curr_particle.Generation()+1); pe.SetWeigth(wi_last); ParticleAtMatrix.push_back(pe); Particle psc(curr_particle.GetType(), E3, z_curr,curr_particle.Generation()+1); psc.SetWeigth(wi_last); ParticleAtMatrix.push_back(psc); return; } } return; }