int history_save(history *hist) { char dir[256]; /* Save the directory */ _dir(hist->path, dir, 256); /* Create the directory to save our data */ if (*dir != 0 && _mkdir(dir) < 0) { fprintf(stderr, "Failed to create directory: %s\n", dir); return -1; } /* Write to file */ FILE *f = fopen(hist->path, "w+"); history_node *node = hist->head; /* Save the history */ while (node) { fprintf(f, "%" PRIu64 ",%" PRIu64 ",%" PRId64 "\n", node->time, node->value, node->out); node = node->next; } fclose(f); return 0; }
void Setting_ProdVTS::on_PB_output_location_clicked() { QString _output_path = QFileDialog::getExistingDirectory( this, tr("Select output folder"), this->output_location, QFileDialog::ShowDirsOnly ); if (!_output_path.isEmpty()) { QDir _dir(_output_path); if(!_dir.exists()) { QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "Warning", "Directory is not exist, do you want to create it?", QMessageBox::Yes|QMessageBox::No); if (reply == QMessageBox::Yes) { _dir.mkpath("."); ui->line_output_location->setText(_dir.absolutePath()); } else ui->line_output_location->setText(QDir(this->default_output_location).absolutePath()); } else ui->line_output_location->setText(_dir.absolutePath()); } else ui->line_output_location->setText(QDir(this->default_output_location).absolutePath()); }
static bool createMimedir(const QString&base,const QString&mimetype) { int pos = 0; int stage = 0; if (base.length()==0) return FALSE; QString _tname = base+"/Documents"; QDir _dir(_tname+"/"+mimetype); if (_dir.exists()) return TRUE; pos = mimetype.find("/"); _dir.setPath(_tname); while (stage<2) { if (!_dir.exists()) { if (!_dir.mkdir(_tname)) { qDebug( QString("Creation of dir %1 failed\n").arg(_tname)); return FALSE; } } switch(stage) { case 0: _tname+="/"+mimetype.left(pos); break; case 1: _tname+="/"+mimetype.right(pos-1); break; default: break; } _dir.setPath(_tname); ++stage; } return TRUE; }
void Setting_ProdVTS::on_line_output_location_editingFinished() { QString line_return = ui->line_output_location->text(); if (!line_return.isEmpty()) { QDir _dir(line_return); if(!_dir.exists()) { ui->line_output_location->blockSignals(true); QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "Warning", "Directory is not exist, do you want to create it?", QMessageBox::Yes|QMessageBox::No); ui->line_output_location->blockSignals(false); if (reply == QMessageBox::Yes) { _dir.mkpath("."); ui->line_output_location->setText(_dir.absolutePath()); } else ui->line_output_location->setText(QDir(this->default_output_location).absolutePath()); } else ui->line_output_location->setText(_dir.absolutePath()); } else ui->line_output_location->setText(QDir(this->default_output_location).absolutePath()); }
QString SimpleTaskManager::STGetTaskFileName(string dir, SimpleTask *task) { QString _dir(dir.c_str()); if(_dir == "") _dir = "."; return QString(_dir) + "/" + QString(QString::number(task->id()) + "-" + task->name().c_str()) + ".stb"; }
// --------------------------------------------------------------------------------- success prepare_storage_directory() { QDir _dir ( storage_dir() ); if ( _dir.exists() ) { return successful(); } if ( _dir.mkpath ( storage_dir() ) ) { return successful(); } return error(); }
/** 角度标准化,这样颜色能单纯点儿 ... */ void DetectWithOF5::normalize_dir(const cv::Mat &dir, cv::Mat &m) { m = cv::Mat::zeros(dir.rows, dir.cols, CV_32F); for (int y = 0; y < dir.rows; y++) { const float *ps = dir.ptr<float>(y); float *pt = m.ptr<float>(y); for (int x = 0; x < dir.cols; x++) { pt[x] = _dirs0[_dir(ps[x])]; } } }
/* * Collide one edgeNode (all edges below it) of this Geom with the triangle * BVH of another geom (b), starting from btriNode. */ void Geom::CollideEdgesTris(int &maxContacts, const BVHNode *edgeNode, const matrix4x4d &transToB, Geom *b, const BVHNode *btriNode, void (*callback)(CollisionContact*)) { if (maxContacts <= 0) return; if (edgeNode->triIndicesStart) { const GeomTree::Edge *edges = this->GetGeomTree()->GetEdges(); int numContacts = 0; vector3f dir; isect_t isect; for (int i=0; i<edgeNode->numTris; i++) { int vtxNum = edges[ edgeNode->triIndicesStart[i] ].v1i; vector3d v1 = transToB * vector3d(&GetGeomTree()->m_vertices[vtxNum]); vector3f _from((float)v1.x, (float)v1.y, (float)v1.z); vector3d _dir( (double)edges[ edgeNode->triIndicesStart[i] ].dir.x, (double)edges[ edgeNode->triIndicesStart[i] ].dir.y, (double)edges[ edgeNode->triIndicesStart[i] ].dir.z); _dir = transToB.ApplyRotationOnly(_dir); dir = vector3f(&_dir.x); isect.dist = edges[ edgeNode->triIndicesStart[i] ].len; isect.triIdx = -1; b->GetGeomTree()->TraceRay(btriNode, _from, dir, &isect); if (isect.triIdx == -1) continue; numContacts++; const double depth = edges[ edgeNode->triIndicesStart[i] ].len - isect.dist; // in world coords CollisionContact contact; contact.pos = b->GetTransform() * (v1 + vector3d(&dir.x)*(double)isect.dist); vector3f n = b->m_geomtree->GetTriNormal(isect.triIdx); contact.normal = vector3d(n.x, n.y, n.z); contact.normal = b->GetTransform().ApplyRotationOnly(contact.normal); contact.dist = isect.dist; contact.depth = depth; contact.triIdx = isect.triIdx; contact.userData1 = m_data; contact.userData2 = b->m_data; // contact geomFlag is bitwise OR of triangle's and edge's flags contact.geomFlag = b->m_geomtree->GetTriFlag(isect.triIdx) | edges[ edgeNode->triIndicesStart[i] ].triFlag; callback(&contact); if (--maxContacts <= 0) return; } } else { CollideEdgesTris(maxContacts, edgeNode->kids[0], transToB, b, btriNode, callback); CollideEdgesTris(maxContacts, edgeNode->kids[1], transToB, b, btriNode, callback); } }
void Raytracer::render( int width, int height, Point3D eye, Vector3D view, Vector3D up, double fov, char* fileName ) { Matrix4x4 viewToWorld; _scrWidth = width; _scrHeight = height; double factor = (double(height)/2)/tan(fov*M_PI/360.0); initPixelBuffer(); viewToWorld = initInvViewMatrix(eye, view, up); //std::cout<<viewToWorld<<std::endl; // Construct a ray for each pixel. for (int i = 0; i < _scrHeight; i++) { for (int j = 0; j < _scrWidth; j++) { Colour col; if (antiAliasing) { col = anti_aliasing(viewToWorld, width, height, factor, i, j); } else { // Sets up ray origin and direction in view space, // image plane is at z = -1. Point3D origin(0, 0, 0); Point3D imagePlane; imagePlane[0] = (-double(width)/2 + 0.5 + j)/factor; imagePlane[1] = (-double(height)/2 + 0.5 + i)/factor; imagePlane[2] = -1; Vector3D _dir (imagePlane[0],imagePlane[1],imagePlane[2]); Vector3D dir = viewToWorld * _dir; origin = viewToWorld * origin;; // TODO: Convert ray to world space and call // shadeRay(ray) to generate pixel colour. Ray3D ray; ray.origin = origin; ray.dir = dir; Colour col = shadeRay(ray); //std:: cout << "i:" <<i << "j:" << j <<"Hit: "<<ray.intersection.none<<std::endl; } _rbuffer[i*width+j] = int(col[0]*255); _gbuffer[i*width+j] = int(col[1]*255); _bbuffer[i*width+j] = int(col[2]*255); } } flushPixelBuffer(fileName); }
char* _std _splitfname(const char *fname, char *dir, char *name) { if (!fname || !name&&!dir) return 0; spstr _dir, _name; splitfname(fname, _dir, _name); if (dir) { strncpy(dir, _dir(), _MAX_PATH); dir[_MAX_PATH-1] = 0; } if (name) { strncpy(name, _name(), _MAX_PATH); name[_MAX_PATH-1] = 0; return name; } else return dir; }
std::pair<SEGMENT,SEGMENT> operator()(const BOUNDS& _bounds, ANGLE _angle) { scalar_type _radius = _bounds.radius(); scalar_type _cos = _radius * cos(_angle*M_PI/180), _sin = _radius * sin(_angle*M_PI/180); vec_type _cross(-_sin,_cos); vec_type _dir(_cos,_sin); point_type _center = _bounds.center(); std::pair<SEGMENT,SEGMENT> _result; _result.first[0] = _center - _cross - _dir; _result.first[1] = _result.first[0] + 2.0*_dir; _result.second[0] = _center + _cross - _dir; _result.second[1] = _result.second[0] + 2.0*_dir; return _result; }
static status_t nfs4_link(fs_volume* volume, fs_vnode* dir, const char* name, fs_vnode* vnode) { VnodeToInode* vti = reinterpret_cast<VnodeToInode*>(vnode->private_node); VnodeToInode* dirVti = reinterpret_cast<VnodeToInode*>(dir->private_node); TRACE("volume = %p, dir = %" B_PRIi64 ", name = %s, vnode = %" B_PRIi64, volume, dirVti->ID(), name, vti->ID()); VnodeToInodeLocker _dir(dirVti); Inode* dirInode = dirVti->Get(); if (dirInode == NULL) return B_ENTRY_NOT_FOUND; VnodeToInodeLocker _(vti); Inode* inode = vti->Get(); if (inode == NULL) return B_ENTRY_NOT_FOUND; return inode->Link(dirInode, name); }
bool Setting_STELA::on_line_soft_location_editingFinished() { QString line_return = ui->line_soft_location->text(); if (!line_return.isEmpty()) { QFileInfo _file(line_return + "/bin/stela.sh"); if(!_file.exists()) { ui->line_soft_location->blockSignals(true); QMessageBox::critical(0, "error", "STELA exe file not found"); ui->line_soft_location->blockSignals(false); ui->line_soft_location->setText(""); return false; } else { QDir _dir(line_return); ui->line_soft_location->setText(_dir.absolutePath()); return true; } } }
Package::Package(QString path, QObject* parent) : QObject(parent), m_metadata(new MetaData) { /* A package roughly looks like this: examplepackage/ |-- actions | |-- silk-webapp-silk-commitlog.desktop | |-- silk-webapp-silk-sidebar.desktop | |-- silk-webapp-silk-sourcetree.desktop | `-- silk-webapp-silk-urltrigger.desktop |-- plugin.desktop |-- scripts | `-- togglesidebar.js `-- webapp.desktop */ //m_metadata->pluginName = QString("silk"); QString installedPath = findPackage(path); if (!installedPath.isEmpty()) { m_root = installedPath; m_metadataFile = m_root.path() + "/" + "metadata.desktop"; readMetadata(); readDir(); //kDebug() << "installed, but valid?" << isValid(); return; } QDir _d(path); if (_d.isRelative()) { path = QDir::currentPath() + "/" + path; } KUrl _dir(path); if (path.isEmpty()) { kDebug() << "Empty package structure"; } else if (path.endsWith(".selkie")) { //kDebug() << "Package file:" << path; //QString unpackPath = "/tmp/unpacked/"; KTempDir tmp; tmp.setAutoRemove(false); //kDebug() << "TempDir:" << tmp.name(); QString unpackPath = tmp.name(); importPackage(path, unpackPath); m_root = KUrl(unpackPath); m_metadataFile = unpackPath + "/" + "metadata.desktop"; readMetadata(); readDir(); } else if (_dir.isValid()) { //kDebug() << "Reading dir" << _dir; m_root = _dir; m_metadataFile = m_root.path() + "/" + "metadata.desktop"; readMetadata(); readDir(); } //show(); }
void RayTracer::InitializeRayList(){ assert(m_pRenderAttribute!=NULL); double factor = (double(this->m_pRenderAttribute->m_iScreenHeight)/2) /tan(this->m_pRenderAttribute->m_ViewFrustrum->m_fFieldOfView*M_PI/360.0); int _height = this->m_pRenderAttribute->m_iScreenHeight; int _width = this->m_pRenderAttribute->m_iScreenWidth; for (int i = 0; i < _height; i++) { for (int j = 0; j < _width; j++) { // Sets up ray origin and direction in view space, // image plane is at z = -1. /** ToDO: * Need to implement anti-aliasing, random sampling. */ if(antiAliasing){ for (int li = -1; li<2; li++) { if (li == 0) { Vector4f origin; Vector4f imagePlane; origin[3] = 1; imagePlane[0] = (-double(_width)/2 + 0.5+j)/factor; imagePlane[1] = (-double(_height)/2 + 0.5+i)/factor; imagePlane[2] = -1; Vector4f _dir (imagePlane[0],imagePlane[1],imagePlane[2]); Vector4f dir = this->m_ViewToWorld * _dir; origin = this->m_ViewToWorld * origin;; Line newrayline; newrayline.m_Direction = dir; newrayline.m_StartPoint = origin; Ray* newray = new Ray(NULL,newrayline,this->m_pRenderAttribute->m_iRayTracingDepth); newray->m_iID = i*_height + j; if(this->m_pRenderAttribute->m_bShadowEnable){ //std::cout<<this->m_LightList.size()<<std::endl; newray->enableShadow(this->m_LightList.size()); } else{ newray->disableShadow(); } m_RayBuffer.push(newray); m_RayList.push_back(newray); } else{ for (int zhuang = -1; zhuang<2; zhuang++) { if (zhuang != 0) { Vector4f origin; Vector4f imagePlane; origin[3] = 1; imagePlane[0] = (-double(_width)/2 + 0.5 +j+ li*0.25)/factor; imagePlane[1] = (-double(_height)/2 + 0.5 +i+ zhuang*0.25)/factor; imagePlane[2] = -1; Vector4f _dir (imagePlane[0],imagePlane[1],imagePlane[2]); Vector4f dir = this->m_ViewToWorld * _dir; origin = this->m_ViewToWorld * origin;; Line newrayline; newrayline.m_Direction = dir; newrayline.m_StartPoint = origin; dir.Normalize(); Ray* newray = new Ray(NULL,newrayline,this->m_pRenderAttribute->m_iRayTracingDepth); newray->m_iID = i*_height + j; if(this->m_pRenderAttribute->m_bShadowEnable){ //std::cout<<this->m_LightList.size()<<std::endl; newray->enableShadow(this->m_LightList.size()); } else{ newray->disableShadow(); } m_RayBuffer.push(newray); m_RayList.push_back(newray); } } } } } else{ Vector4f origin; Vector4f imagePlane; origin[3] = 1; imagePlane[0] = (-double(_width)/2 + 0.5 + j)/factor; imagePlane[1] = (-double(_height)/2 + 0.5 + i)/factor; imagePlane[2] = -1; Vector4f _dir (imagePlane[0],imagePlane[1],imagePlane[2]); Vector4f dir = this->m_ViewToWorld * _dir; origin = this->m_ViewToWorld * origin;; Line newrayline; newrayline.m_Direction = dir; newrayline.m_StartPoint = origin; dir.Normalize(); Ray* newray = new Ray(NULL,newrayline,this->m_pRenderAttribute->m_iRayTracingDepth); newray->m_iID = i*_height + j; if(this->m_pRenderAttribute->m_bShadowEnable){ //std::cout<<this->m_LightList.size()<<std::endl; newray->enableShadow(this->m_LightList.size()); } else{ newray->disableShadow(); } m_RayBuffer.push(newray); m_RayList.push_back(newray); } // } } std::cout<<"Ray List Initialize, Total Number Of Ray: "<<m_RayBuffer.size()<<std::endl; }