Beispiel #1
0
void TreeNode::getMinMax( TreeCoord& minSib, TreeCoord& maxSib )
//--------------------------------------------------------------
{
    bool        vert = (_parent->getDirection() == TreeVertical);
    TreeCoord   tmpx, tmpy;
    int         i;

    for( i = getCount( ChildList ); i > 0; i -= 1 ) {
        TreeNode * node = getNode( ChildList, i - 1 );
        if( node->_flags.placed > Arranging && node->_flags.enabled != Hidden ) {

            node->getMinSibCoord( tmpx, tmpy );
            minSib = maxCoord( minSib, vert ? tmpx : tmpy );

            break;
        }
    }

    for( i = getCount( ChildList ); i > 0; i -= 1 ) {
        TreeNode * node = getNode( ChildList,  i - 1 );
        if( node->_flags.enabled > Hidden ) {
            node->getMinCoord( tmpx, tmpy );
            minSib = minCoord( minSib, vert ? tmpx : tmpy );

            node->getMaxCoord( tmpx, tmpy );
            maxSib = maxCoord( maxSib, vert ? tmpx : tmpy );
        }
    }
}
void Scene_polyhedron_shortest_path_item::get_as_edge_point(Scene_polyhedron_shortest_path_item::Face_location& inOutLocation)
{
  size_t minIndex = 0;
  FT minCoord(inOutLocation.second[0]);
  
  for (size_t i = 1; i < 3; ++i)
  {
    if (minCoord > inOutLocation.second[i])
    {
      minIndex = i;
      minCoord = inOutLocation.second[i];
    }
  }
  
  // The nearest edge is that of the two non-minimal barycentric coordinates
  size_t nearestEdge[2];
  size_t current = 0;
  
  for (size_t i = 0; i < 3; ++i)
  {
    if (i != minIndex)
    {
      nearestEdge[current] = i;
      ++current;
    }
  }

  Construct_barycentric_coordinate construct_barycentric_coordinate;

  Point_3 trianglePoints[3] = { 
    m_shortestPaths->point(inOutLocation.first, construct_barycentric_coordinate(FT(1.0), FT(0.0), FT(0.0))),
    m_shortestPaths->point(inOutLocation.first, construct_barycentric_coordinate(FT(0.0), FT(1.0), FT(0.0))),
    m_shortestPaths->point(inOutLocation.first, construct_barycentric_coordinate(FT(0.0), FT(0.0), FT(1.0))),
  };
  
  CGAL::Surface_mesh_shortest_paths_3::Parametric_distance_along_segment_3<Surface_mesh_shortest_path_traits> parametricDistanceSegment3;
  
  Point_3 trianglePoint = m_shortestPaths->point(inOutLocation.first, inOutLocation.second);
  
  FT distanceAlongSegment = parametricDistanceSegment3(trianglePoints[nearestEdge[0]], trianglePoints[nearestEdge[1]], trianglePoint);
  
  FT coords[3] = { FT(0.0), FT(0.0), FT(0.0), };
  
  coords[nearestEdge[1]] = distanceAlongSegment;
  coords[nearestEdge[0]] = FT(1.0) - distanceAlongSegment;

  inOutLocation.second = construct_barycentric_coordinate(coords[0], coords[1], coords[2]);
}
Beispiel #3
0
ParticleShape* GLWidget::createParticleShape(const QString& system, Mesh* mesh)
{
	glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
        float* pos = new float[mesh->vboSize*3];
        glGetBufferSubData(GL_ARRAY_BUFFER,0,mesh->vboSize*3*sizeof(float),pos);
        float3 minCoord(FLT_MAX,FLT_MAX,FLT_MAX);
        float3 maxCoord(-FLT_MAX,-FLT_MAX,-FLT_MAX);
        for(int i = 0; i < mesh->vboSize; i++)
	{
            float x=pos[(i*3)],y=pos[(i*3)+1],z=pos[(i*3)+2];
            if(x<minCoord.x)
                minCoord.x=x;
            if(x>maxCoord.x)
                maxCoord.x=x;
            if(y<minCoord.y)
                minCoord.y=y;
            if(y>maxCoord.y)
                maxCoord.y=y;
            if(z<minCoord.z)
                minCoord.z=z;
            if(z>maxCoord.z)
                maxCoord.z=z;
	}
	delete[] pos;
	pos =0;
            float space = systems[system]->getSpacing();
            ParticleShape* shape = new ParticleShape(minCoord,maxCoord,space);


            shape->voxelizeMesh(mesh->vbo,mesh->ibo,mesh->iboSize);
            //RenderUtils::write3DTextureToDisc(shape->getVoxelTexture(),shape->getVoxelResolution(),s.str().c_str());
            //shape->voxelizeSurface(me->vbo,me->ibo,me->iboSize);
            //s<<"surface";
            //RenderUtils::write3DTextureToDisc(shape->getSurfaceTexture(),shape->getVoxelResolution(),s.str().c_str());

            /*dout<<"mesh name = "<<s.str()<<endl;
            dout<<"maxCoord dim = "<<shape->getMaxDim()<<endl;
            dout<<"minCoord dim = "<<shape->getMinDim()<<endl;
            dout<<"Trans = "<<trans<<endl;
            dout<<"minCoord ("<<shape->getMin().x<<","<<shape->getMin().y<<","<<shape->getMin().z<<")"<<endl;
            dout<<"voxel res = "<<shape->getVoxelResolution()<<endl;
            dout<<"spacing = "<<space<<endl;*/

            return shape;

}
void Adapt::ElementSizeFieldBase<EvalT, Traits>::
getCellRadius(const std::size_t cell, typename EvalT::MeshScalarT& cellRadius) const
{
  std::vector<MeshScalarT> maxCoord(3,-1e10);
  std::vector<MeshScalarT> minCoord(3,+1e10);

  for (int v=0; v < numVertices; ++v) {
    for (int k=0; k < numDims; ++k) {
      if(maxCoord[k] < coordVec_vertices(cell,v,k)) maxCoord[k] = coordVec_vertices(cell,v,k);
      if(minCoord[k] > coordVec_vertices(cell,v,k)) minCoord[k] = coordVec_vertices(cell,v,k);
    }
  }

  cellRadius = 0.0;
  for (int k=0; k < numDims; ++k)
    cellRadius += (maxCoord[k] - minCoord[k]) *  (maxCoord[k] - minCoord[k]);

  cellRadius = std::sqrt(cellRadius) / 2.0;

}
void
WaitWorld::operator()() {

    //CONSOLE << "(WaitWorld)\t";

    // # «десь не можем использовать this->world().
    auto w = std::static_pointer_cast< World >( mElement.lock() );

    // провер¤ем наличие контейнеров в верхних ¤чейках и
    // создаЄм на месте пустых ¤чеек новые конейнеры
    const auto is = w->incarnateSet();
    typelib::coord2Int_t  cc( 0, w->maxCoord().y );
    for (cc.x = w->minCoord().x; cc.x <= w->maxCoord().x; ++cc.x) {
        // @test
        //if (cc.x != w->minCoord().x) { continue; }

        const std::shared_ptr< Incarnate > container =
            w->element< Container >( cc );
        if ( container ) {
            // место по этой координате зан¤то
            continue;
        }

        // @test воплощаем 1 элемент в мире
        //if (w->incarnateSet().size() >= 2) { break; }

        // место по этой координате пустует
        const nameElement_t name = Container::nextRandom();
        w->incarnateContainer( name, cc );

        // воплощаем 1 элемент за раз
        //break;

    } // for (cc.x = ...

}
Beispiel #6
0
bool TreeNode::resolveChildWard( TreeRect & r )
//---------------------------------------------
{
    bool       vert = _parent->getDirection() == TreeVertical;
    TreeCoord  minSib = vert ? r.x() : r.y();
    TreeCoord  maxSib = 0;
    TreeCoord  childOff = childSep / 2;
    TreeCoord  maxChild = 0;
    bool       minSet = false;
    int        maxLevel;
    int        minLevel;
    int        i;

    for( i = 0; i < getCount( FlatList ); i += 1 ) {
        TreeNode * node = getNode( FlatList, i );

        int tLevel = node->getLevel();
        if( node->_flags.enabled > Hidden && tLevel >= 0 ) {
            if( minSet ) {
                maxLevel = maxInt( maxLevel, tLevel );
                minLevel = minInt( minLevel, tLevel );
            } else {
                maxLevel = tLevel;
                minLevel = tLevel;
                minSet = true;
            }
        }
    }

    if( !minSet ) {
        return false;
    }

    for( int level = minLevel; level <= maxLevel; level += 1 ) {
        maxChild = 0;
        for( i = 0; i < getCount( FlatList ); i += 1 ) {
            TreeNode * node = getNode( FlatList, i );
            if( node->getLevel() == level && node->_flags.enabled > Hidden ) {
                vert ? node->_bounding.y( childOff )
                     : node->_bounding.x( childOff );

                maxChild = maxCoord( maxChild, vert ? node->_bounding.h()
                                                    : node->_bounding.w() );
                maxSib = maxCoord( maxSib, vert ? node->_descend.x() + node->_descend.w()
                                                : node->_descend.y() + node->_descend.h() );
                minSib = minCoord( minSib, vert ? node->_descend.x()
                                                : node->_descend.y() );
            }
        }
        childOff += maxChild + childSep;
    }

    if( vert ) {
        r.x( minSib );
        r.w( maxSib - r.x() );
        r.h( childOff );
        _descend.h( childOff );
    } else {
        r.w( childOff );
        r.y( minSib );
        r.h( maxSib - r.y() );
        _descend.w( childOff );
    }

    return true;
}
 void pop_back(){
   minCoord().pop_back();
   maxCoord().pop_back();
   _partNumber.pop_back();
 }
 void push_back(const FormulaPtr& b,const FormulaPtr& e, unsigned int f){
   minCoord().push_back(b);
   maxCoord().push_back(e);
   _partNumber.push_back(f);
 }
 void reserve(size_t n) {
   minCoord().reserve(n);
   maxCoord().reserve(n);
   _partNumber.reserve(n);
 }
void Adapt::ElementSizeField<PHAL::AlbanyTraits::Residual, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
  double value;

  if( this->outputCellAverage ) { // nominal radius

    // Get shards Array (from STK) for this workset
    Albany::MDArray data = (*workset.stateArrayPtr)[this->className + "_Cell"];
    std::vector<int> dims;
    data.dimensions(dims);
    int size = dims.size();


    for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
          this->getCellRadius(cell, value);
//          data(cell, (std::size_t)0) = ADValue(value);
          data(cell, (std::size_t)0) = value;
    }
  }

  if( this->outputQPData ) { // x_\xi \cdot x_\xi, x_\eta \cdot x_\eta, x_\zeta \cdot x_\zeta

    // Get shards Array (from STK) for this workset
    Albany::MDArray data = (*workset.stateArrayPtr)[this->className + "_QP"];
    std::vector<int> dims;
    data.dimensions(dims);
    int size = dims.size();


    for (std::size_t cell = 0; cell < workset.numCells; ++cell) {
          this->getCellRadius(cell, value);
//          data(cell, (std::size_t)0) = ADValue(value);
          data(cell, (std::size_t)0) = value;
    }
/*
    for (std::size_t cell=0; cell < workset.numCells; ++cell) {
      for (std::size_t qp=0; qp < numQPs; ++qp) {
        for (std::size_t i=0; i < numDims; ++i) { // loop over \xi, \eta, \zeta
          data(cell, qp, i) = 0.0;
          for (std::size_t j=0; j < numDims; ++j) {
            data(cell, qp, i) += coordVec(cell, qp, j) * wGradBF(cell, node, qp, j);
            for (std::size_t alpha=0; alpha < numDims; ++alpha) {
              Gc(cell,qp,i,j) += jacobian_inv(cell,qp,alpha,i)*jacobian_inv(cell,qp,alpha,j);
            }
          }
        }
      }
    }
*/

  }

  if( this->outputNodeData ) { // nominal radius, store as nodal data that will be scattered and summed

    // Get the node data block container
    Teuchos::RCP<Adapt::NodalDataBlock> node_data =
      this->pStateMgr->getStateInfoStruct()->getNodalDataBase()->getNodalDataBlock();
    Teuchos::ArrayRCP<ST> data = node_data->getLocalNodeView();
    Teuchos::ArrayRCP<Teuchos::ArrayRCP<GO> >  wsElNodeID = workset.wsElNodeID;
    Teuchos::RCP<const Tpetra_BlockMap> local_node_map = node_data->getLocalMap();

    int l_nV = this->numVertices;
    int l_nD = this->numDims;

    int  node_var_offset;
    int  node_var_ndofs;
    int  node_weight_offset;
    int  node_weight_ndofs;
    node_data->getNDofsAndOffset(this->className + "_Node", node_var_offset, node_var_ndofs);
    node_data->getNDofsAndOffset(this->className + "_NodeWgt", node_weight_offset, node_weight_ndofs);

    for (int cell = 0; cell < workset.numCells; ++cell) { // loop over all elements in workset

      std::vector<double> maxCoord(3,-1e10);
      std::vector<double> minCoord(3,+1e10);

      // Get element width in x, y, z
      for (int v=0; v < l_nV; ++v) { // loop over all the "corners" of each element
        for (int k=0; k < l_nD; ++k) { // loop over each dimension of the problem
          if(maxCoord[k] < this->coordVec_vertices(cell,v,k)) maxCoord[k] = this->coordVec_vertices(cell,v,k);
          if(minCoord[k] > this->coordVec_vertices(cell,v,k)) minCoord[k] = this->coordVec_vertices(cell,v,k);
        }
      }

      if(this->isAnisotropic) //An-isotropic
        // Note: code assumes blocksize of blockmap is numDims + 1 - the last entry accumulates the weight
        for (int node = 0; node < l_nV; ++node) { // loop over all the "corners" of each element

          GO global_block_id = wsElNodeID[cell][node]; // get the global id of this node
          LO local_block_id = local_node_map->getLocalBlockID(global_block_id);

          // skip the node if it is not owned by me
          if(local_block_id == Teuchos::OrdinalTraits<LO>::invalid()) continue;
          LO first_local_dof = local_node_map->getFirstLocalPointInLocalBlock(local_block_id);

          // accumulate 1/2 of the element width in each dimension - into each element corner
          for (int k=0; k < node_var_ndofs; ++k)
//            data[global_node][k] += ADValue(maxCoord[k] - minCoord[k]) / 2.0;
            data[first_local_dof + node_var_offset + k] += (maxCoord[k] - minCoord[k]) / 2.0;

          // save the weight (denominator)
          data[first_local_dof + node_weight_offset] += 1.0;

      } // end anisotropic size field

      else // isotropic size field
        // Note: code assumes blocksize of blockmap is 1 + 1 = 2 - the last entry accumulates the weight
        for (int node = 0; node < l_nV; ++node) { // loop over all the "corners" of each element

          GO global_block_id = wsElNodeID[cell][node]; // get the global id of this node
          LO local_block_id = local_node_map->getLocalBlockID(global_block_id);

          // skip the node if it is not owned by me
          if(local_block_id == Teuchos::OrdinalTraits<LO>::invalid()) continue;
          LO first_local_dof = local_node_map->getFirstLocalPointInLocalBlock(local_block_id);

          // save element radius, just a scalar
          for (int k=0; k < l_nD; ++k) {
//            data[global_node][k] += ADValue(maxCoord[k] - minCoord[k]) / 2.0;
            data[first_local_dof + node_var_offset] += (maxCoord[k] - minCoord[k]) / 2.0;
            // save the weight (denominator)
            data[first_local_dof + node_weight_offset] += 1.0;

          }


          // the above calculates the average of the element width, depth, and height when
          // divided by the accumulated weights

      } // end isotropic size field
    } // end cell loop
  } // end node data if

}
Beispiel #11
0
// Main execute funcion---------------------------------------------------------------------------------
vector<FP> QrDetectorMod::find() {
	Mat gray = Mat(image.rows, image.cols, CV_8UC1);
	Mat edges(image.size(), CV_MAKETYPE(image.depth(), 1));
	cvtColor(image, gray, CV_BGR2GRAY);
	Canny(gray, edges, 100, 200, 3);
	//imshow("edges", edges);
	vector<vector<Point>> contours;
	vector<Point> approx;

	//findContours(edges, contours, RETR_LIST, CHAIN_APPROX_NONE); 
	uchar** arr = matToArr(edges); /* trik use pointers for images*/ findContours_(arr, &contours);
	/*for (int i = 0; i < contours.size() - 1; i++){
		vector<Point> fst = contours[i];
		for (int j = i + 1; j < contours.size() - 1; j++){
			vector<Point> scd = contours[j];
			double endbeg = dist(fst[fst.size() - 1], scd[0]);
			double endend = dist(fst[fst.size() - 1], scd[scd.size() - 1]);
			double begbeg = dist(fst[0], scd[0]);
			double begend = dist(fst[0], scd[scd.size() - 1]);
			
			if (endbeg < 2){
				fst.insert(fst.end(), scd.begin(), scd.end());
				contours[i] = fst;
				contours.erase(contours.begin() + j);
			}
			if (begbeg < 2){
				reverse(fst.begin(), fst.end());
				fst.insert(fst.end(), scd.begin(), scd.end());
				contours[i] = fst;
				contours.erase(contours.begin() + j);
			}
			else
			if (endend < 2){
				fst.insert(fst.end(), scd.begin(), scd.end());
				contours[i] = fst;
				contours.erase(contours.begin() + j);
			}
			else
			if (begend < 2){
				scd.insert(scd.end(), fst.begin(), fst.end());
				contours[j] = scd;
				contours.erase(contours.begin() + i);
			}

		}
	}*/
	/*RNG rng(12345);
	for each (vector<Point> c in contours){
		Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
		for each(Point p in c) circle(image, p, 1, color, -1);
	}*/

	for (int i = 0; i < contours.size(); i++)
	{
		approx = approximate(contours[i]);
		//for each (Point p in approx) circle(image, Point(p.x, p.y), 1, Scalar(0, 0, 255), -1); // for degug
		if (approx.size() == 4){
			//drawContours(image, contours, i, Scalar(255, 0, 0), CV_FILLED); //for debug
			if (isQuad(&approx) && abs(area(approx)) > 10){
				if (!inOtherContour(&approx)){
					quadList.push_back(vector<Point>(approx));
				}
			}
		}
	}

	if (quadList.size() < 2){
		return vector<FP>();
	}
	vector<FP> fps;
	for each(vector<Point> quad in quadList){

		Point min = minCoord(quad);
		Point max = maxCoord(quad);
		int x = min.x - 0.7*(max.x - min.x),
			y = min.y - 0.7*(max.y - min.y);
		if (x < 0) x = 0; if (y < 0) y = 0;
			
		int	w = 2.8 * (max.x - min.x),
			h = 2.8 * (max.y - min.y);
		if (h > 0.7*image.rows || w > 0.7*image.cols) continue;
		if (x + w > gray.cols) w = gray.cols - x - 1;
		if (h + y > gray.rows) h = gray.rows - y - 1;

		Mat partImg = gray(Rect(x, y, w, h));
		threshold(partImg, partImg, 128, 255, THRESH_OTSU); 
		int dif = quad[4].y - y;
		if (dif >= h || dif <= 0) continue;
		if (singleHorizontalCheck(partImg, dif)) {
			fps.push_back(FP(quad[4].x, quad[4].y, module));
			}
		else {
			if (fullHorizontalCheck(partImg)) {
				fps.push_back(FP(quad[4].x, quad[4].y, module));				}
		}
			//imshow("Parts", partImg);//for debug
			//waitKey(1200);//for debug
		}