layer(int input_size, int hidden_size, double cost = 0) : cost_{cost} { std::random_device rd; std::default_random_engine re(rd()); std::uniform_real_distribution<T> ur(0, 1); ur(re); w1_.resize(hidden_size, input_size); w2_.resize(input_size, hidden_size); b1_ = EigenMat::Zero(hidden_size, 1); b2_ = EigenMat::Zero(input_size, 1); for(size_t row = 0; row != w1_.rows(); ++row){ for(size_t col = 0; col != w1_.cols(); ++col){ w1_(row, col) = ur(re); } } for(size_t row = 0; row != w2_.rows(); ++row){ for(size_t col = 0; col != w2_.cols(); ++col){ w2_(row, col) = ur(re); } } double const R = std::sqrt(6) / std::sqrt(hidden_size + input_size + 1); w1_ = w1_.array() * 2 * R - R; w2_ = w2_.array() * 2 * R - R; w1_grad_ = EigenMat::Zero(hidden_size, input_size); w2_grad_ = EigenMat::Zero(input_size, hidden_size); b1_grad_ = EigenMat::Zero(hidden_size, 1); b2_grad_ = EigenMat::Zero(input_size, 1); }
void EllipseSelection::advance() { currentpt(0)++; if(currentpt(0) > ur(0)) { currentpt(0) = ll(0); currentpt(1)++; } if(currentpt(1) > ur(1)) done_ = true; }
void RectangleSelection::next() { currentpt(0)++; if(currentpt(0) > ur(0)) { currentpt(0) = ll(0); currentpt(1)++; } if(currentpt(1) > ur(1)) done_ = true; }
//--------------------------------------------------------------------------- void Sky::renderSolid(TSRenderContext &rc) { GFXSurface *gfxSurface = rc.getSurface(); TS::PointArray *pointArray = rc.getPointArray(); TSCamera *camera = rc.getCamera(); gfxSurface->setFillMode(GFX_FILL_CONSTANT); gfxSurface->setHazeSource(GFX_HAZE_NONE); gfxSurface->setShadeSource(GFX_SHADE_NONE); gfxSurface->setAlphaSource(GFX_ALPHA_NONE); gfxSurface->setTexturePerspective(FALSE); gfxSurface->setTransparency(FALSE); setFillColor(gfxSurface, skyIndex, skyColor); RectI vp = rc.getCamera()->getScreenViewport(); Point3F ul(vp.upperL.x, vp.upperL.y, W_DIST); Point3F ur(vp.lowerR.x, vp.upperL.y, W_DIST); Point3F lr(vp.lowerR.x, vp.lowerR.y, W_DIST); Point3F ll(vp.upperL.x, vp.lowerR.y, W_DIST); gfxSurface->setZTest(GFX_ZWRITE); gfxSurface->addVertex(&ul); gfxSurface->addVertex(&ur); gfxSurface->addVertex(&lr); gfxSurface->addVertex(&ll); gfxSurface->emitPoly(); gfxSurface->setZTest(GFX_ZTEST_AND_WRITE); }
int sc_main(int argc, char* argv[]) { sc_signal<char> i1, i2, i3; sc_signal<char>d1, o1, o2, o3, o4; sc_signal<bool>sr; sc_signal<bool>clk; change_case cc("cc"); filter ft("ft"); m_bus mb("mb"); driver dr("dr"); monitor mon("mon"); UART ur("ur"); arbiter ar("ar"); dr.d_char(d1); cc.char_in(d1); cc.char_out(o1); ft.char_in(d1); ft.char_out(o2); ar.selector(sr); ar.clk(clk); mb.char_in1(o1); mb.char_in2(o2); mb.char_out(o3); mb.selector(sr); ur.char_in(o3); ur.char_out(o4); mon.clk(clk); mon.m_char(o4); sc_start(); return 0; }
void CUndoRedoManager::Repalace( CellType type,int eventType ) { CURCell ur(type,eventType); m_preStack.pop_back(); m_preStack.push_back(ur); m_nexStack.clear(); }
// Jacobians: dg(b,u)/db, dg(b,u)/du void linearizeCarDynamics(const Matrix<C_DIM>& c, const Matrix<U_DIM>& u, Matrix<C_DIM,C_DIM>& F, Matrix<C_DIM,U_DIM>& G, Matrix<C_DIM>& h) { Matrix<X_DIM,1> x; x.insert(0, 0, c); x.insert(C_DIM, 0, x0.subMatrix<L_DIM,1>(C_DIM,0)); F.reset(); Matrix<X_DIM> xr(x), xl(x), ddx; for (size_t i = 0; i < C_DIM; ++i) { xr[i] += step; xl[i] -= step; ddx = (dynfunc(xr, u, zeros<Q_DIM,1>()) - dynfunc(xl, u, zeros<Q_DIM,1>())) / (xr[i] - xl[i]); F.insert(0,i, ddx.subMatrix<C_DIM,1>(0, 0)); xr[i] = x[i]; xl[i] = x[i]; } G.reset(); Matrix<U_DIM> ur(u), ul(u); Matrix<X_DIM> ddg; for (size_t i = 0; i < U_DIM; ++i) { ur[i] += step; ul[i] -= step; ddg = (dynfunc(x, ur, zeros<Q_DIM,1>()) - dynfunc(x, ul, zeros<Q_DIM,1>())) / (ur[i] - ul[i]); G.insert(0,i, ddg.subMatrix<C_DIM,1>(0, 0)); ur[i] = u[i]; ul[i] = u[i]; } h = dynfunc(x, u, zeros<Q_DIM,1>()).subMatrix<C_DIM,1>(0,0); }
// Computes sum of the values of a unitary blob on grid points. The blob is // supposed to be at the origin of the absolute coordinate system double sum_blob_SimpleGrid(const struct blobtype &blob, const SimpleGrid &grid, const Matrix2D<double> *D) { SPEED_UP_temps012; Matrix1D<double> gr(3), ur(3), corner1(3), corner2(3); double actual_radius; int i, j, k; double sum = 0.0; // Compute the limits of the blob in the grid coordinate system grid.universe2grid(vectorR3(-blob.radius, -blob.radius, -blob.radius), corner1); grid.universe2grid(vectorR3(blob.radius, blob.radius, blob.radius), corner2); if (D != NULL) box_enclosing(corner1, corner2, *D, corner1, corner2); // Compute the sum in the points inside the grid // The integer part of the vectors is taken for not picking points // just in the border of the blob, which we know they are 0. for (i = (int)XX(corner1); i <= (int)XX(corner2); i++) for (j = (int)YY(corner1); j <= (int)YY(corner2); j++) for (k = (int)ZZ(corner1); k <= (int)ZZ(corner2); k++) { VECTOR_R3(gr, i, j, k); grid.grid2universe(gr, ur); if (D != NULL) M3x3_BY_V3x1(ur, *D, ur); actual_radius = ur.module(); if (actual_radius < blob.radius) sum += kaiser_value(actual_radius, blob.radius, blob.alpha, blob.order); } return sum; }
ossimProjection* ossimNitfProjectionFactory::makeBilinear( const ossimNitfImageHeader* hdr, const std::vector<ossimGpt>& gpts) const { double rows = hdr->getNumberOfRows(); double cols = hdr->getNumberOfCols(); ossimDpt ul(0.0, 0.0); ossimDpt ur(cols-1.0, 0.0); ossimDpt lr(cols-1.0, rows-1.0); ossimDpt ll(0.0, rows-1.0); ossimRefPtr<ossimBilinearProjection> proj; try { proj = new ossimBilinearProjection(ul, ur, lr, ll, gpts[0], gpts[1], gpts[2], gpts[3]); } catch(...) { proj = 0; } return proj.release(); }
void ttrss_urlreader::reload() { urls.clear(); tags.clear(); alltags.clear(); file_urlreader ur(file); ur.reload(); std::vector<std::string>& file_urls(ur.get_urls()); for(std::vector<std::string>::iterator it=file_urls.begin(); it!=file_urls.end(); it++) { if (it->substr(0,6) == "query:") { urls.push_back(*it); std::vector<std::string>& file_tags(ur.get_tags(*it)); tags[*it] = ur.get_tags(*it); for (std::vector<std::string>::iterator jt=file_tags.begin(); jt!=file_tags.end(); jt++) { alltags.insert(*jt); } } } std::vector<tagged_feedurl> feedurls = api->get_subscribed_urls(); for (std::vector<tagged_feedurl>::iterator it=feedurls.begin(); it!=feedurls.end(); it++) { LOG(LOG_DEBUG, "added %s to URL list", it->first.c_str()); urls.push_back(it->first); tags[it->first] = it->second; for (std::vector<std::string>::iterator jt=it->second.begin(); jt!=it->second.end(); jt++) { LOG(LOG_DEBUG, "%s: added tag %s", it->first.c_str(), jt->c_str()); alltags.insert(*jt); } } }
//******************************************************************* // Public Method: //******************************************************************* bool rspfDrect::intersects(const rspfDrect& rect) const { if(rect.hasNans() || hasNans()) { return false; } if (theOrientMode != rect.theOrientMode) return false; rspf_float64 ulx = rspf::max(rect.ul().x,ul().x); rspf_float64 lrx = rspf::min(rect.lr().x,lr().x); rspf_float64 uly, lry; bool rtn=false; if (theOrientMode == RSPF_LEFT_HANDED) { uly = rspf::max(rect.ul().y,ul().y); lry = rspf::min(rect.lr().y,lr().y); rtn = ((ulx <= lrx) && (uly <= lry)); } else { uly = rspf::max(rect.ll().y,ll().y); lry = rspf::min(rect.ur().y,ur().y); rtn = ((ulx <= lrx) && (uly <= lry)); } return (rtn); }
bool FeatureClassWidget::applyChanges() { VERIFY(mpFeatureClass != NULL && mpEditFeatureClass != NULL); FeatureClass::ClippingType origType = mpEditFeatureClass->getClippingType(); if (mpNoClipButton->isChecked()) { mpEditFeatureClass->setClippingType(FeatureClass::NO_CLIP); } if (mpSceneClipButton->isChecked()) { mpEditFeatureClass->setClippingType(FeatureClass::SCENE_CLIP); } if (mpSpecifiedClipButton->isChecked()) { //if the clipping corners have changed in any way, then set //mbDisplayOnlyChanges to false to force a reload of shapes std::pair<LocationType, LocationType> clipping = mpFeatureClass->getClipping(); mpEditFeatureClass->setClippingType(FeatureClass::NO_CLIP); LocationType ll(mpSouthEdit->getValue(), mpEastEdit->getValue()); LocationType ur(mpNorthEdit->getValue(), mpWestEdit->getValue()); if (ll.mX != clipping.first.mX || ll.mY != clipping.first.mY || ur.mX != clipping.second.mX || ur.mY != clipping.second.mY) { mbDisplayOnlyChanges = false; } mpEditFeatureClass->setClipping(ll, ur); } if (origType != mpEditFeatureClass->getClippingType()) { //if the clipping type has changed, then set mbDisplayOnlyChanges //to false to force a reload of the shapes mbDisplayOnlyChanges = false; } //in this function, we are going to check if sufficient changes were made //in the dialog to require a reload of the shapefile if (mpEditFeatureClass->setConnectionParameters(mpConnection->getConnectionParameters()) == true) { mbDisplayOnlyChanges = false; } mpDisplay->applyChanges(); //copy the edit feature class back into the primary feature class mpFeatureClass->fromDynamicObject(mpEditFeatureClass->toDynamicObject().get()); //now copy the data that is current state related that does not get written //to the file mpFeatureClass->copyQueryGraphicIds(mpEditFeatureClass->getQueries()); mpFeatureClass->setLayerName(mpLayerNameEdit->text().toStdString()); //if the queries determining which data is loaded have changed in //any way, then set mbDisplayOnlyChanges to false to force the reload if (compareQueriesForChanges(mpFeatureClass->getQueries()) == true) { mbDisplayOnlyChanges = false; } return true; }
// cases 4-7 void test_disjoint_corner() { bool all_pass = false; rect_list_type cliprects; rect_type mainrect(40,40,20,20); rect_type ul(35,55,10,10); rect_type ur(55,55,10,10); rect_type ll(35,35,10,10); rect_type lr(55,35,10,10); // upper left cliprects = disjoint_union(mainrect, ul); rect_type ul_1(35, 55, 5, 5); rect_type ul_2(35, 60, 10, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, ul_1) && \ rect_list_contains(cliprects, ul_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: upper left\n"); } // lower left cliprects = disjoint_union(mainrect, ll); rect_type ll_1(35, 35, 10, 5); rect_type ll_2(35, 40, 5, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, ll_1) && \ rect_list_contains(cliprects, ll_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: upper left\n"); } // upper right cliprects = disjoint_union(mainrect, ur); rect_type ur_1(55, 60, 10, 5); rect_type ur_2(60, 55, 5, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, ur_1) && \ rect_list_contains(cliprects, ur_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: upper right\n"); } // lower right cliprects = disjoint_union(mainrect, lr); rect_type lr_1(55, 35, 10, 5); rect_type lr_2(60, 40, 5, 5); all_pass = (cliprects.size() == 3) && rect_list_contains(cliprects, lr_1) && \ rect_list_contains(cliprects, lr_2) && rect_list_contains(cliprects, mainrect); if (!all_pass) { printf("Error in test_disjoint_corner()i: lower right\n"); } }
inline Matrix<_xDim,_uDim> dfdu(Matrix<_xDim> (*f)(const Matrix<_xDim>&, const Matrix<_uDim>&), const Matrix<_xDim>& x, const Matrix<_uDim>& u) { Matrix<_xDim,_uDim> B; Matrix<_uDim> ur(u), ul(u); for (size_t i = 0; i < _uDim; ++i) { ur[i] += step; ul[i] -= step; B.insert(0,i, (f(x, ur) - f(x, ul)) / (2.0*step)); ur[i] = ul[i] = u[i]; } return B; }
glm::vec3 Material::GetImageColorInterp(const glm::vec2 &uv_coord, const QImage* const& image) { if(image == NULL || uv_coord.x < 0 || uv_coord.y < 0 || uv_coord.x >= 1.0f || uv_coord.y >= 1.0f) { return glm::vec3(1,1,1); } else { //Use bilinear interp. float X = image->width() * uv_coord.x; float Y = image->height() * (1.0f - uv_coord.y); glm::vec2 floors = glm::vec2(floor(X), floor(Y)); glm::vec2 ceils = glm::vec2(ceil(X), ceil(Y)); ceils = glm::min(ceils, glm::vec2(image->width()-1, image->height()-1)); QColor qll = image->pixel(floors.x, floors.y); glm::vec3 ll(qll.red(), qll.green(), qll.blue()); QColor qlr = image->pixel(ceils.x, floors.y); glm::vec3 lr(qlr.red(), qlr.green(), qlr.blue()); QColor qul = image->pixel(floors.x, ceils.y); glm::vec3 ul(qul.red(), qul.green(), qul.blue()); QColor qur = image->pixel(ceils.x, ceils.y); glm::vec3 ur(qur.red(), qur.green(), qur.blue()); float distX = (X - floors.x); glm::vec3 color_low = ll * (1-distX) + lr * distX; glm::vec3 color_high = ul * (1-distX) + ur * distX; float distY = (Y - floors.y); glm::vec3 result = (color_low * (1 - distY) + color_high * distY)/255.0f; return result; glm::vec2 XY(X,Y); //Want floor and ceil of both X and Y //Do square interp of <X,Y> float dist_ll = glm::distance(XY, floors); float dist_lr = glm::distance(XY, glm::vec2(ceils.x, floors.y)); float dist_ul = glm::distance(XY, glm::vec2(floors.x, ceils.y)); float dist_ur = glm::distance(XY, ceils); float sum = dist_ll + dist_lr + dist_ul + dist_ur; float llc = (1 - dist_ll/sum); float lrc = (1 - dist_lr/sum); float ulc = (1 - dist_ul/sum); float urc = (1 - dist_ur/sum); float checksum = llc + lrc + ulc + urc; glm::vec3 final_color = llc * ll + lrc * lr + ulc * ul + urc * ur; return final_color/255.0f; } }
//******************************************************************* // Public Method: rspfDrect::clipToRect //******************************************************************* rspfDrect rspfDrect::clipToRect(const rspfDrect& rect)const { rspfDrect result; result.makeNan(); if(rect.hasNans() || hasNans()) { return result; } if (theOrientMode != rect.theOrientMode) return (*this); double x0 = rspf::max(rect.ul().x, ul().x); double x1 = rspf::min(rect.lr().x, lr().x); double y0, y1; if (theOrientMode == RSPF_LEFT_HANDED) { y0 = rspf::max(rect.ll().y, ll().y); y1 = rspf::min(rect.ur().y, ur().y); if( (x1 < x0) || (y1 < y0) ) return result; else result = rspfDrect(x0, y0, x1, y1, theOrientMode); } else { y0 = rspf::max(rect.ll().y,ll().y); y1 = rspf::min(rect.ur().y,ur().y); if((x0 <= x1) && (y0 <= y1)) { result = rspfDrect(x0, y1, x1, y0, theOrientMode); } } return result; }
int ::BordersReader<Pix>::surroundingEdges() { static const Pix transp(transparent<Pix>()); Pix ll((m_pos.x > 0 && m_pos.y > 0) ? *(m_pix - m_wrap - 1) : transp); Pix lr((m_pos.x < m_lx && m_pos.y > 0) ? *(m_pix - m_wrap) : transp); Pix ul((m_pos.x > 0 && m_pos.y < m_ly) ? *(m_pix - 1) : transp); Pix ur((m_pos.x < m_lx && m_pos.y < m_ly) ? *(m_pix) : transp); if (ll == ur || lr == ul) return 2; int nEquals = (int)(ll == lr) + (int)(lr == ur) + (int)(ur == ul) + (int)(ul == ll); return 4 - nEquals; }
PropertyHelper<URect>::return_type PropertyHelper<URect>::fromString(const String& str) { URect ur(UVector2(UDim(0.0f, 0.0f), UDim(0.0f, 0.0f)), UVector2(UDim(0.0f, 0.0f), UDim(0.0f, 0.0f))); if (str.empty()) return ur; std::stringstream& sstream = SharedStringstream::GetPreparedStream(str); sstream >> ur; if (sstream.fail()) throwParsingException(getDataTypeName(), str); return ur; }
void CrwMap::extract0x102a(const CiffComponent& ciffComponent, const CrwMapInfo* crwMapInfo, Image& image, ByteOrder byteOrder) { if (ciffComponent.typeId() != unsignedShort) { return extractBasic(ciffComponent, crwMapInfo, image, byteOrder); } long aperture = 0; long shutterSpeed = 0; std::string ifdItem(ExifTags::ifdItem(canonCs2IfdId)); uint16_t c = 1; while (uint32_t(c)*2 < ciffComponent.size()) { uint16_t n = 1; ExifKey key(c, ifdItem); UShortValue value; value.read(ciffComponent.pData() + c*2, n*2, byteOrder); image.exifData().add(key, &value); if (c == 21) aperture = value.toLong(); if (c == 22) shutterSpeed = value.toLong(); c += n; } // Exif.Photo.FNumber float f = fnumber(canonEv(aperture)); // Beware: primitive conversion algorithm uint32_t den = 1000000; uint32_t nom = static_cast<uint32_t>(f * den); uint32_t g = gcd(nom, den); URational ur(nom/g, den/g); URationalValue fn; fn.value_.push_back(ur); image.exifData().add(ExifKey("Exif.Photo.FNumber"), &fn); // Exif.Photo.ExposureTime ur = exposureTime(canonEv(shutterSpeed)); URationalValue et; et.value_.push_back(ur); image.exifData().add(ExifKey("Exif.Photo.ExposureTime"), &et); } // CrwMap::extract0x102a
Rectx<Type> Rectx<Type>::get_rot_bounds(const Vec2<Type> &hotspot, const Angle &angle) const { //Find the rotated positions of each corner Rectx<Type> retVal(*this); Vec2<Type> ul(retVal.left, retVal.top); ul.rotate(hotspot, angle); Vec2<Type> ur(retVal.right, retVal.top); ur.rotate(hotspot, angle); Vec2<Type> ll(retVal.left, retVal.bottom); ll.rotate(hotspot, angle); Vec2<Type> lr (retVal.right, retVal.bottom); lr.rotate(hotspot, angle); //Use the sidemost corners as the bounds of the new rectangle retVal.left = min(min(ul.x, ur.x), min(ll.x, lr.x)); retVal.right = max(max(ul.x, ur.x), max(ll.x, lr.x)); retVal.top = min(min(ul.y, ur.y), min(ll.y, lr.y)); retVal.bottom = max(max(ul.y, ur.y), max(ll.y, lr.y)); return retVal; }
/* ** Gets the user associated with the email address. ** Only retrieves the user from the database if the user ** is not set or if the email changed. ** Returns true if the user changed (or has just been set), ** false otherwise. */ bool UIConnection::getUser(std::string const &email) { bool retrieveFromDB = true; if (_user) { retrieveFromDB = _user->getEmail() != email; } if (retrieveFromDB) { UserRepository ur(_database); std::unique_ptr<Database::transaction_type> t(_database.getTransaction()); try { auto user = ur.getByEmail(email); _user = std::move(user); } catch (odb::exception const &e) { std::cerr << "Exception: ODB: " << e.what() << std::endl; t->rollback(); } } return (retrieveFromDB); }
void googlereader_urlreader::reload() { urls.clear(); tags.clear(); alltags.clear(); if (cfg->get_configvalue_as_bool("googlereader-show-special-feeds")) { std::vector<std::string> tmptags; ADD_URL(BROADCAST_FRIENDS_URL, std::string("~") + _("People you follow")); ADD_URL(STARRED_ITEMS_URL, std::string("~") + _("Starred items")); ADD_URL(SHARED_ITEMS_URL, std::string("~") + _("Shared items")); ADD_URL(POPULAR_ITEMS_URL, std::string("~") + _("Popular items")); } file_urlreader ur(file); ur.reload(); std::vector<std::string>& file_urls(ur.get_urls()); for(std::vector<std::string>::iterator it=file_urls.begin();it!=file_urls.end();it++) { if (it->substr(0,6) == "query:") { urls.push_back(*it); std::vector<std::string>& file_tags(ur.get_tags(*it)); tags[*it] = ur.get_tags(*it); for (std::vector<std::string>::iterator jt=file_tags.begin();jt!=file_tags.end();jt++) { alltags.insert(*jt); } } } std::vector<tagged_feedurl> feedurls = api->get_subscribed_urls(); for (std::vector<tagged_feedurl>::iterator it=feedurls.begin();it!=feedurls.end();it++) { LOG(LOG_DEBUG, "added %s to URL list", it->first.c_str()); urls.push_back(it->first); tags[it->first] = it->second; for (std::vector<std::string>::iterator jt=it->second.begin();jt!=it->second.end();jt++) { LOG(LOG_DEBUG, "%s: added tag %s", it->first.c_str(), jt->c_str()); alltags.insert(*jt); } } }
/** * Creates a grid mesh. * * @param n_x the number of grid cells on the X axis * @param n_y the number of grid cells on the Y axis * @param width the width X of the grid (normalized) * @param height the height Y of the grid (normalized) * @param spacing the spacing between cells (normalized) * @param conf_func a function to call to configure the grid (or NULL) */ void Mesh::make_grid(int n_x, int n_y, double width, double height, double spacing, grid_configuration_func conf_func) { double side_width = (width - (n_x - 1) * spacing) / n_x; double side_height = (height - (n_y - 1) * spacing) / n_y; for (int i = 0; i < n_x; i++) { for (int j = 0; j < n_y; j++) { LibMatrix::vec3 a(-width / 2 + i * (side_width + spacing), height / 2 - j * (side_height + spacing), 0); LibMatrix::vec3 b(a.x(), a.y() - side_height, 0); LibMatrix::vec3 c(a.x() + side_width, a.y(), 0); LibMatrix::vec3 d(a.x() + side_width, a.y() - side_height, 0); if (!conf_func) { std::vector<float> ul(vertex_size_); std::vector<float> ur(vertex_size_); std::vector<float> ll(vertex_size_); std::vector<float> lr(vertex_size_); set_attrib(0, a, &ul); set_attrib(0, c, &ur); set_attrib(0, b, &ll); set_attrib(0, d, &lr); next_vertex(); vertices_.back() = ul; next_vertex(); vertices_.back() = ll; next_vertex(); vertices_.back() = ur; next_vertex(); vertices_.back() = ll; next_vertex(); vertices_.back() = lr; next_vertex(); vertices_.back() = ur; } else { conf_func(*this, i, j, n_x, n_y, a, b, c, d); } } } }
/// Accumulate pose based on velocity void step(double dt=1){ mVelScale = dt; double amt = 1.-smooth(); // TODO: adjust for dt //Vec3d angVel = mSpin0 + mTurn; // low-pass filter velocities mMove1.lerp(mMove0*dt + mNudge, amt); mSpin1.lerp(mSpin0*dt + mTurn, amt); // turn and nudge are a one-shot increments, so clear each frame mTurn.set(0); mNudge.set(0); mQuat *= vel().quat(); updateDirectionVectors(); // accumulate position: for(int i=0; i<pos().size(); ++i){ pos()[i] += mMove1.dot(Vec3d(ur()[i], uu()[i], uf()[i])); } }
/* Sum spline on a grid ---------------------------------------------------- */ double sum_spatial_Bspline03_SimpleGrid(const SimpleGrid &grid) { Matrix1D<double> gr(3), ur(3), corner1(3), corner2(3); int i, j, k; double sum = 0.0; // Compute the limits of the spline in the grid coordinate system grid.universe2grid(vectorR3(-2.0, -2.0, -2.0), corner1); grid.universe2grid(vectorR3(2.0, 2.0, 2.0), corner2); // Compute the sum in the points inside the grid // The integer part of the vectors is taken for not picking points // just in the border of the spline, which we know they are 0. for (i = (int)XX(corner1); i <= (int)XX(corner2); i++) for (j = (int)YY(corner1); j <= (int)YY(corner2); j++) for (k = (int)ZZ(corner1); k <= (int)ZZ(corner2); k++) { VECTOR_R3(gr, i, j, k); grid.grid2universe(gr, ur); sum += spatial_Bspline03(ur); } return sum; }
void Ground::triangulateForDisplay() { // i, j = 0, 0 is the lower left corner of the array for (int i = 0; i < (this->nRows - 1); i++) { for (int j = 0; j < (this->nCols - 1); j++) { Coord2i ll(i, j); // Lower left Coord2i lr(i, j+1); // Lower right Coord2i ul(i+1, j); // Upper left Coord2i ur(i+1, j+1); // Upper right Coord3f p1 = this->toCoord(ll); Coord3f p2 = this->toCoord(lr); Coord3f p3 = this->toCoord(ur); Coord3f p4 = this->toCoord(ul); Color3f c1 = this->colorAt(p1, ll); Color3f c2 = this->colorAt(p2, lr); Color3f c3 = this->colorAt(p3, ur); Color3f c4 = this->colorAt(p4, ul); Coord3f n1 = this->normalAt(ll); Coord3f n2 = this->normalAt(lr); Coord3f n3 = this->normalAt(ur); Coord3f n4 = this->normalAt(ul); this->displayVector.push_back(Triangle(p1, p3, p4, c1, c3, c4, n1, n3, n4)); this->displayVector.push_back(Triangle(p1, p2, p3, c1, c2, c3, n1, n2, n3)); } } // exit(1); }
void GMSHAdaptiveMeshDensity::getQuadTreeGeometry(std::vector<GeoLib::Point*> &pnts, std::vector<GeoLib::Polyline*> &plys) const { std::list<GeoLib::QuadTree<GeoLib::Point>*> leaf_list; _quad_tree->getLeafs(leaf_list); for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it(leaf_list.begin()); it != leaf_list.end(); ++it) { // fetch corner points from leaf GeoLib::Point *ll(new GeoLib::Point), *ur(new GeoLib::Point); (*it)->getSquarePoints(*ll, *ur); std::size_t pnt_offset (pnts.size()); pnts.push_back(ll); pnts.push_back(new GeoLib::Point((*ur)[0], (*ll)[1], 0.0)); pnts.push_back(ur); pnts.push_back(new GeoLib::Point((*ll)[0], (*ur)[1], 0.0)); plys.push_back(new GeoLib::Polyline(pnts)); plys[plys.size() - 1]->addPoint(pnt_offset); plys[plys.size() - 1]->addPoint(pnt_offset + 1); plys[plys.size() - 1]->addPoint(pnt_offset + 2); plys[plys.size() - 1]->addPoint(pnt_offset + 3); plys[plys.size() - 1]->addPoint(pnt_offset); } }
void WCModeSketchRectangleCreate::OnMouseMove(const WPFloat &x, const WPFloat &y) { //Get suggestion from workbench this->_xSuggest = this->_workbench->SnapMouseX(); this->_ySuggest = this->_workbench->SnapMouseY(); this->_suggestionType = this->_workbench->SuggestAlignment(this->_alignRules, NULL, this->_xSuggest, this->_ySuggest); //Move p1 if we are drawing if (this->_isDrawing) { //Get new corner positions for the rectangle WCVector4 ll = this->_begin; WCVector4 ul(this->_begin.I(), this->_ySuggest, 0.0, 1.0); WCVector4 ur(this->_xSuggest, this->_ySuggest, 0.0, 1.0); WCVector4 lr(this->_xSuggest, this->_begin.J(), 0.0, 1.0); ll = this->_workbench->Sketch()->ReferencePlane()->TransformMatrix() * ll; ul = this->_workbench->Sketch()->ReferencePlane()->TransformMatrix() * ul; ur = this->_workbench->Sketch()->ReferencePlane()->TransformMatrix() * ur; lr = this->_workbench->Sketch()->ReferencePlane()->TransformMatrix() * lr; //Set the end points of the lines appropriately this->_lines[0]->Begin(ll); this->_lines[0]->End(ul); this->_lines[1]->Begin(ul); this->_lines[1]->End(ur); this->_lines[2]->Begin(ur); this->_lines[2]->End(lr); this->_lines[3]->Begin(lr); this->_lines[3]->End(ll); } }
GameObject* Terrain::CreateGameObject(const char* diffuseTxt_filename, const char* normalTxt_filename, const char* heightTxt_filemane) { std::vector<float2> texture_coordinate = calculateTextureCoordiate(); std::vector<float2> boundsY = CalcAllPatchBoundsY(); const int iNumVertices = m_initInfo.HeightmapWidth / 8 * (m_initInfo.HeightmapHeight) / 8 * 4; const int iNumIndices = iNumVertices; VertexTerrain* vertices = new VertexTerrain[iNumVertices]; unsigned int* indices = new unsigned int[iNumIndices]; // Translate the terrain, so that the mid-point of terrain is at (0, 0, 0) Matrix4 translate; translate.CreateTranslation(Vector3(-GetWidth() / 2.0f, 0.0f, -GetDepth() / 2.0f)); // Initialize the index to the vertex buffer. int indexCounter = 0; // Load the vertex and index array with the terrain data. for (int j = 0; j < m_initInfo.HeightmapHeight - 8; j += 8) { for (int i = 0; i < m_initInfo.HeightmapWidth - 8; i += 8) { const int index_bl = m_initInfo.HeightmapWidth * j + i; const int index_br = m_initInfo.HeightmapWidth * j + (i + 8); const int index_ul = m_initInfo.HeightmapWidth * (j + 8) + i; const int index_ur = m_initInfo.HeightmapWidth * (j + 8) + (i + 8); const float2 bl_uv( texture_coordinate[index_bl].x, texture_coordinate[index_bl].y ); const float2 br_uv( (texture_coordinate[index_br].x == 0.0f ? 1.0f : texture_coordinate[index_br].x), texture_coordinate[index_br].y ); const float2 ul_uv( texture_coordinate[index_ul].x, (texture_coordinate[index_ul].y == 1.0f ? 0.0f : texture_coordinate[index_ul].y) ); const float2 ur_uv( (texture_coordinate[index_ur].x == 0.0f ? 1.0f : texture_coordinate[index_ur].x), (texture_coordinate[index_ur].y == 1.0f ? 0.0f : texture_coordinate[index_ur].y) ); Vector3 bl(i * m_initInfo.CellSpacing, m_HeightMap[index_bl] * m_initInfo.CellSpacing, j* m_initInfo.CellSpacing); Vector3 br((i + 8)* m_initInfo.CellSpacing, m_HeightMap[index_br] * m_initInfo.CellSpacing, j* m_initInfo.CellSpacing); Vector3 ul(i* m_initInfo.CellSpacing, m_HeightMap[index_ul] * m_initInfo.CellSpacing, (j + 8)* m_initInfo.CellSpacing); Vector3 ur((i + 8)* m_initInfo.CellSpacing, m_HeightMap[index_ur] * m_initInfo.CellSpacing, (j + 8)* m_initInfo.CellSpacing); const int patch_id = j + (i / m_initInfo.CellsPerPatch); // bottom left { vertices[indexCounter].m_pos = bl; vertices[indexCounter].m_UV[0] = bl_uv.x; vertices[indexCounter].m_UV[1] = bl_uv.y; vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x; vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y; indices[indexCounter] = indexCounter; indexCounter++; } // bottom right { vertices[indexCounter].m_pos = br; vertices[indexCounter].m_UV[0] = br_uv.x; vertices[indexCounter].m_UV[1] = br_uv.y; vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x; vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y; indices[indexCounter] = indexCounter; indexCounter++; } // upper left { vertices[indexCounter].m_pos = ul; vertices[indexCounter].m_UV[0] = ul_uv.x; vertices[indexCounter].m_UV[1] = ul_uv.y; vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x; vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y; indices[indexCounter] = indexCounter; indexCounter++; } // upper right { vertices[indexCounter].m_pos = ur; vertices[indexCounter].m_UV[0] = ur_uv.x; vertices[indexCounter].m_UV[1] = ur_uv.y; vertices[indexCounter].m_boundsY[0] = boundsY[patch_id].x; vertices[indexCounter].m_boundsY[1] = boundsY[patch_id].y; indices[indexCounter] = indexCounter; indexCounter++; } } } std::string diffuseTxt_filepath = std::string("../Assets/") + diffuseTxt_filename; std::string normalTxt_filepath = std::string("../Assets/") + normalTxt_filename; std::string heightTxt_filepath = std::string("../Assets/") + heightTxt_filemane; MeshData* meshData = new MeshData(vertices, iNumVertices, indices, iNumIndices, sizeof(VertexTerrain)); meshData->SetBoundingBox(AABB(Vector3(0, 0, 0), Vector3(m_initInfo.HeightmapHeight, 0, m_initInfo.HeightmapWidth))); Handle hMeshComp(sizeof(MeshComponent)); new (hMeshComp) MeshComponent(meshData); SceneGraph::GetInstance()->AddComponent((MeshComponent*) hMeshComp.Raw()); RenderPass* renderPass = new RenderPass; renderPass->SetVertexShader("../DEngine/Shaders/VS_terrain.hlsl"); renderPass->SetHullShader("../DEngine/Shaders/HS_terrain.hlsl"); renderPass->SetDomainShader("../DEngine/Shaders/DS_terrain.hlsl"); renderPass->SetPixelShader("../DEngine/Shaders/PS_terrain.hlsl"); Handle hTexture1(sizeof(Texture)); new (hTexture1) Texture(Texture::SHADER_RESOURCES, 1, diffuseTxt_filepath.c_str()); Handle hTexture2(sizeof(Texture)); new (hTexture2) Texture(Texture::SHADER_RESOURCES, 1, normalTxt_filepath.c_str()); Handle hTexture3(sizeof(Texture)); new (hTexture3) Texture(Texture::SHADER_RESOURCES, 1, heightTxt_filepath.c_str()); renderPass->AddTexture(hTexture1); renderPass->AddTexture(hTexture2); renderPass->AddTexture(hTexture3); renderPass->SetTopology(D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST); renderPass->SetBlendState(State::NULL_STATE); renderPass->SetRenderTargets(D3D11Renderer::GetInstance()->m_pRTVArray, 2); renderPass->SetDepthStencilView(D3D11Renderer::GetInstance()->m_depth->GetDSV()); renderPass->SetDepthStencilState(State::DEFAULT_DEPTH_STENCIL_DSS); renderPass->SetRasterizerState(State::CULL_BACK_RS); ((MeshComponent*) hMeshComp.Raw())->m_pMeshData->m_Material.AddPassToTechnique(renderPass); GameObject* terrain = new GameObject; terrain->AddComponent((Component*) hMeshComp.Raw()); delete[] vertices; delete[] indices; return terrain; }
selpt(Line *dl,Point p) { int s,m,prop; Rectangle r; Line *l=dl; for (m = 0; l; l = l->next) { r = l->r; prop = 0; switch (l->type) { case LINE: if (EQ(p,P)) l->sel = 3; else if (EQ(p,Q)) l->sel = 12; else if (Y == p.y && Y == V && (p.x-X)*(U-p.x) > 0) prop = 1; else if (X == p.x && X == U && (p.y-Y)*(V-p.y) > 0) prop = 1; else continue; m |= (l->mod |= LINEHIT); if (prop) { l->sel = 15; m |= selbox(dl,canon(r)); } break; case BOX: case MACRO: if (EQ(p,ul(r))) selborder(dl,l->sel=3,r); else if (EQ(p,lr(r))) selborder(dl,l->sel=12,r); else if (EQ(p,ll(r))) selborder(dl,l->sel=9,r); else if (EQ(p,ur(r))) selborder(dl,l->sel=6,r); else if (l->type == BOX && IN(p,r)) { l->sel = 15; m |= selbox(dl,r); } else continue; m |= (l->mod |= BOXHIT); break; case INST: if (WITHIN(p,r)) { l->sel = 15; m |= (l->mod |= BOXHIT) | selbox(dl,r); } break; case DOTS: if (EQ(p,ul(r))) l->sel=3; else if (EQ(p,lr(r))) l->sel=12; else if (EQ(p,ll(r))) l->sel=9; else if (EQ(p,ur(r))) l->sel=6; else if (IN(p,r)) l->sel = 15; else continue; m |= (l->mod |= DOTHIT); break; case STRING: if (EQ(p,P)) { l->sel = 3; m |= (l->mod |= STRHIT); } break; } } return m; }