void hgeh::render_circle_slice( HGE *hge, const Vec2D center, float radius, int segments, float begin, float end, DWORD color ) { const float increment = ( end - begin ) / segments; float theta = begin; typedef std::vector<Vec2D> Positions; Positions positions; for( int i = 0; i < segments; ++i ) { Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) ); p *= radius; p += center; positions.push_back( p ); theta += increment; } for( Positions::iterator it = positions.begin(); it != positions.end(); ) { Vec2D p1 = *it; ++it; Vec2D p2; if( it != positions.end() ) { p2 = *it; } else { break; } hge->Gfx_RenderLine( p1.x, p1.y, p2.x, p2.y, color ); } }
void hgeh::render_circle_slice( HGE *hge, float x, float y, float radius, int segments, float begin, float end, DWORD color ) { const float increment = ( end - begin ) / segments; float theta = begin; const Vec2D center( x, y ); typedef std::vector<Vec2D> Positions; Positions positions; for( int i = 0; i < segments + 1; ++i ) { Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) ); p *= radius; p += center; positions.push_back( p ); theta += increment; } render_lines( hge, positions, color ); Vec2D first = Vec2D( std::cos( begin ), std::sin( begin ) ) * radius + center; Vec2D last = Vec2D( std::cos( end ), std::sin( end ) ) * radius + center; //-1 correct point hge->Gfx_RenderLine( center.x - 1, center.y, first.x, first.y, color ); hge->Gfx_RenderLine( center.x, center.y, last.x, last.y, color ); }
void AnimatedBoardView::removeItems(const Logic::Locations& locs) { Positions positions; positions.reserve(locs.size()); std::transform(locs.begin(), locs.end(), std::back_inserter(positions), [=](Logic::Location l) { return grid->toPosition(l); }); animator->addDisappearingAnimation(positions); }
TextBreaks::Positions TextBreaks::sentenceBreaks(const QString & text) { Positions breaks; if (text.isEmpty()) return breaks; int i=0; do { if (i == 0 || isSentenceSeparator(text[i])) { Position pos; while (i < text.length() && !text[i].isLetter()) { i++; } pos.start = i; do { i++; } while (i < text.length() && !isSentenceSeparator(text[i])); pos.length = i - pos.start; // null-terminated, hence more than 1 if (pos.length > 1) breaks.append(pos); } else { i++; } } while (i < text.length()); return breaks; }
void Trajectory::shiftIntoBox(Positions &p) { if (p.getBox().empty()) return; const vector<Vector3D> &box = p.getBox(); if (offsets.size() < p.size()) offsets.resize(p.size()); // NOTE: This method was stolen from: // gromacs-4.5.4/src/gmxlib/rmpbc.c:rm_gropbc() // With the difference that we are accumulating offsets over the whole // trajectory. for (unsigned n = 1; n < p.size(); n++) { Vector3D orig = p[n]; p[n] += offsets[n]; for (int m = 2; 0 <= m; m--) { double dist; while (0.75 * box[m][m] < fabs(dist = p[n][m] - p[n - 1][m])) { if (10 * box[m][m] < fabs(dist)) break; // Ignore unreasonable if (0 < dist) for (int d = 0; d <= m; d++) p[n][d] -= box[m][d]; else for (int d = 0; d <= m; d++) p[n][d] += box[m][d]; } } offsets[n] = p[n] - orig; LOG_DEBUG(5, "SHIFT: " << n << ' ' << p[n] << ' ' << offsets[n]); } }
TextBreaks::Positions TextBreaks::wordBreaks(const QString &text) { Positions breaks; if (text.isEmpty()) { return breaks; } int i=0; do { if (i == 0 || isWordSeparator(text[i])) { Position pos; // Seek past leading separators while (i < text.length() && isWordSeparator(text[i])) { i++; } pos.start = i; while (i < text.length() && !isWordSeparator(text[i])) { i++; } pos.length = i - pos.start; if (pos.length > 0) { breaks.append(pos); } } else { i++; } } while (i < text.length()); return breaks; }
int main() { test_symmetry(Symmetry()); test_symmetry(HORIZONTAL_REFLECTION); test_symmetry(VERTICAL_REFLECTION); test_symmetry(ROTATION_180); test_symmetry(DIAGONAL_REFLECTION); test_symmetry(ANTIDIAGONAL_REFLECTION); test_symmetry(join(HORIZONTAL_REFLECTION, HORIZONTAL_REFLECTION)); test_symmetry(join(HORIZONTAL_REFLECTION, VERTICAL_REFLECTION)); test_symmetry(join(HORIZONTAL_REFLECTION, ROTATION_180)); test_symmetry(join(HORIZONTAL_REFLECTION, DIAGONAL_REFLECTION)); test_symmetry(join(HORIZONTAL_REFLECTION, ANTIDIAGONAL_REFLECTION)); Positions p; p.assign(false); for (unsigned int i = 0; i < 9; ++i) { p[i] = true; p[i + 72] = true; p[9 * i] = true; p[9 * i + 8] = true; } assert(HORIZONTAL_REFLECTION.satisfies(p)); assert(VERTICAL_REFLECTION.satisfies(p)); assert(ROTATION_180.satisfies(p)); assert(DIAGONAL_REFLECTION.satisfies(p)); assert(ANTIDIAGONAL_REFLECTION.satisfies(p)); return 0; }
bool XTCReader::read(Positions &positions, Topology *topology) { #if HAVE_GROMACS if (setjmp(gromacs_error_handler())) THROW("Failed to read XTC"); int step = 0; real time = 0; matrix box; real prec = 0; gmx_bool bOK = 0; int ret; if (first) { ret = read_first_xtc(p->file, &natoms, &step, &time, box, &p->x, &prec, &bOK); first = false; } else ret = read_next_xtc(p->file, natoms, &step, &time, box, p->x, &prec, &bOK); if (!ret) return false; Vector3D bounds = Vector3D(box[0][0], box[1][1], box[2][2]) * 10; LOG_DEBUG(3, "Read XTC frame: ret=" << ret << " natoms=" << natoms << " step=" << step << " time=" << time << " box=" << bounds << " prec=" << prec << " bOK=" << bOK); vector<Vector3D> _box(3); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) _box[i][j] = box[i][j] * 10; positions.setBox(_box); // Get number of atoms unsigned count; if (topology) count = topology->getAtoms().size(); else count = natoms; if (natoms < (int)count) count = natoms; for (unsigned i = 0; i < count; i++) { // Get atom index unsigned index = 0; if (topology) index = topology->getAtoms()[i].getIndex(); if (!index) index = i; // Store the position Vector3D pos = Vector3D(((rvec *)p->x)[index][0], ((rvec *)p->x)[index][1], ((rvec *)p->x)[index][2]) * 10; positions.push_back(pos); LOG_DEBUG(5, "XTC: " << i << '/' << count << ' ' << pos); } return true; #else THROWS("Not compiled with Gromacs support"); #endif }
static double alignment(const Positions &p1, const Positions &p2) { // Computes a metric of how aligned the two sets of positions are double d = 0; // Only consider every 8th position for better performance for (unsigned i = 1; i < p1.size(); i += 8) d += p1[i].distanceSquared(p2[i]); return sqrt(d) * 8 / p1.size(); }
void print_csv(const std::string & filename){ using namespace MVD3; const std::string delim = "; "; MVD3File file(filename); const size_t n_neuron = file.getNbNeuron(); std::cout << "GID; POSITION_X; POSITION_Y; POSITION_Z; ROTATION_Q0; ROTATION_Q1; ROTATION_Q2; ROTATION_Q3;"; std::cout << " MORPHO; MTYPE; ETYPE; SYNCLASS;" << "\n"; size_t offset=0, size_read=0; size_t gid=0; while(offset < n_neuron){ size_read = std::min(n_neuron-offset, size_t(200)); const Range read_range = Range(offset, size_read); const Positions positions = file.getPositions(read_range); const Rotations rotations = file.getRotations(read_range); const std::vector<std::string> morphos = file.getMorphologies(read_range); const std::vector<std::string> mtypes = file.getMtypes(read_range); const std::vector<std::string> etypes = file.getEtypes(read_range); const std::vector<std::string> syn_class = file.getSynapseClass(read_range); assert( size_read == positions.shape()[0] && size_read == rotations.shape()[0] && size_read == morphos.size() && size_read == mtypes.size() && size_read == etypes.size() && size_read == syn_class.size()); for(size_t i =0; i < size_read; ++i){ std::cout << gid << delim; for(size_t j=0; j < 3; ++j){ std::cout << positions[i][j] << delim; } for(size_t j=0; j < 4; ++j){ std::cout << rotations[i][j] << delim; } std::cout << morphos[i] << delim; std::cout << mtypes[i] << delim; std::cout << etypes[i] << delim; std::cout << syn_class[i] << delim; std::cout << "\n"; ++gid; } offset += size_read; } }
static void Draw( Renderable* RThis, const r3dCamera& Cam ) { ParticleRenderable *This = static_cast<ParticleRenderable*>( RThis ); #ifndef FINAL_BUILD if( r_show_draw_order->GetInt() == 2 ) { extern Positions gDEBUG_DrawPositions ; gDEBUG_DrawPositions.PushBack( This->Parent->GetPosition() ); } #endif This->Parent->DrawParticles( Cam ); }
void XYZReader::read(Positions &positions, Topology *topology) { istream &stream = source.getStream(); vector<string> tokens; char line[1024]; // Read header line stream.getline(line, 1024); if (stream.fail()) THROWS("Failed to read XYZ"); // Get atom count String::tokenize(line, tokens); if (tokens.size() < 1) THROW("Missing atom count in XYZ"); unsigned count = String::parseU32(tokens[0]); unsigned lineNum = 1; // Reset positions.clear(); if (topology) topology->clear(); // Read atoms and positions while (!stream.fail() && count) { stream.getline(line, 1024); lineNum++; tokens.clear(); String::tokenize(line, tokens); if (tokens.size() < 1 || !isdigit(tokens[0][0])) continue; if (tokens.size() < 5) THROWS("Invalid XYZ file at line: " << lineNum); if (topology) { Atom atom(tokens[1]); atom.setIndex(String::parseU32(tokens[0])); topology->add(atom); } positions.push_back(Vector3D(String::parseDouble(tokens[2]), String::parseDouble(tokens[3]), String::parseDouble(tokens[4]))); count--; } positions.init(); if (count) THROWS("Failed reading XYZ, expected " << count << " more atoms"); }
void Trajectory::alignToLast(Positions &p) { // This function uses a random search, similar to simulated annealing, to // find a rotation of the current positions which is close to the previous. // This helps stabilize the view of the protein and improve interpolation // between frames. if (empty() || p.empty()) return; const Positions &last = *back(); double align = alignment(p, last); double start = align; double angle = 2 * M_PI; unsigned rounds = 64; const double magicStoppingPoint = 0.3; double rate = pow(4.0 / 360.0, 1.0 / rounds); // Within 4 degrees for (unsigned j = 0; magicStoppingPoint < align && j < rounds; j++) { for (unsigned l = 0; l < 2; l++) { uint8_t r = Random::instance().rand<uint8_t>(); Vector3D v(!(r & 1), !(r & 2), !(r & 4)); AxisAngleD a(angle * l ? -1 : 1, v.normalize()); // Rotate Positions tmp(p); for (unsigned i = 0; i < p.size(); i++) tmp[i] = a.rotate(tmp[i]); // Recheck double newAlign = alignment(tmp, last); if (newAlign < align) { // Accept align = newAlign; p = tmp; } } angle *= rate; } if (magicStoppingPoint <= start) LOG_DEBUG(3, "Alignment start=" << start << " end=" << align << " improved " << String::printf("%0.2f%%", (1.0 - align / start) * 100)); }
void TapAndHoldDetector::initGesture( const Positions& positions ) { cancelGesture(); if( !positions.empty( )) { _touchStartPos = positions; _tapAndHoldTimer.start(); } }
void hgeh::render_circle( HGE *hge, float x, float y, float radius, int segments, DWORD color ) { const float increment = math::PI2 / segments; float theta = 0.0f; const Vec2D center( x, y ); typedef std::vector<Vec2D> Positions; Positions positions; for( int i = 0; i < segments; ++i ) { Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) ); p *= radius; p += center; positions.push_back( p ); theta += increment; } render_lines( hge, positions, color, true ); }
void DoubleTapDetector::initGesture(const Positions& positions) { if (!_canBeDoubleTap) { // adding initial points if (positions.size() > _touchStartPos.size()) { if (_touchStartPos.empty()) _startGesture(positions); else _touchStartPos = positions; return; } // all points released, decide if potential double tap or abort if (positions.empty()) { _canBeDoubleTap = _doubleTapTimer.isActive(); if (!_canBeDoubleTap) cancelGesture(); } return; } // points pressed again, check for double tap if (positions.size() == _touchStartPos.size() && !MathUtils::hasMoved(positions, _touchStartPos, _doubleTapThresholdPx)) { emit doubleTap(MathUtils::computeCenter(_touchStartPos), _touchStartPos.size()); _doubleTapTimer.stop(); } // all points released, reset everything for next detection if (positions.empty()) cancelGesture(); }
void hgeh::render_solid_circle_slice( HGE *hge, const Vec2D center, float radius, int segments, float begin, float end, DWORD color ) { const float increment = ( end - begin ) / segments; float theta = begin; typedef std::vector<Vec2D> Positions; Positions positions; for( int i = 0; i < segments; ++i ) { Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) ); p *= radius; p += center; positions.push_back( p ); theta += increment; } for( Positions::iterator it = positions.begin(); it != positions.end(); ) { Vec2D p1 = *it; ++it; Vec2D p2; if( it != positions.end() ) { p2 = *it; } else { p2 = *positions.begin(); } hgeTriple t; t.blend = BLEND_DEFAULT; t.tex = 0; hgeVertex v; v.col = color; v.tx = 0.0; v.ty = 0.0; v.x = center.x; v.y = center.y; t.v[0] = v; v.x = p1.x; v.y = p1.y; t.v[1] = v; v.x = p2.x; v.y = p2.y; t.v[2] = v; hge->Gfx_RenderTriple( &t ); } }