Example #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 );
        }
    }
}
Example #2
0
void TreeNode::arrangeAll( TreeDirection dir, TreeRootList& roots,
                           TreeRect& world, OutputDevice *dev )
//----------------------------------------------------------------
{
    TreeCoord   maxX = 0;
    TreeCoord   maxY = 0;
    TreeCoord   sibOff = sibSep;
    int         i;

    for( i = 0; i < roots.count(); i += 1 ) {
        if( roots[ i ]->enabled() ) {
            TreeCoord  sibStart = sibOff;
            TreeRect   r;
            TreeNode * node = roots[ i ]->setNode();

            roots[ i ]->setRingEnable();
            roots[ i ]->setAllBounding( dev );

            node->arrangeTree( sibOff );

            // now mop up any nodes isolated by hiding
            for( int j = node->getCount( FlatList ); j > 0; j -= 1 ) {
                TreeNode * newNode = node->getNode( FlatList, j - 1 );
                if( newNode->_flags.placed != Placed ) {
                    newNode->arrangeTree( sibOff );
                }
            }

            if( dir == TreeVertical ) {
                r.x( sibStart );
                r.y( sibSep );
            } else {
                r.y( sibStart );
                r.x( sibSep );
            }
            if( node->resolveChildWard( r ) ) {
                roots[ i ]->setBound( r );          // set the roots bounding box
                roots[ i ]->sortEdges();

                sibOff = ( dir == TreeVertical) ? r.x() + r.w() + sibSep
                                                : r.y() + r.h() + sibSep;

                maxX = maxCoord( maxX, r.x() + r.w() );
                maxY = maxCoord( maxY, r.y() + r.h() );
            } else {
                roots[ i ]->setEnable( false );
            }
        }
    }

    world.w( maxX );
    world.h( maxY );
}
Example #3
0
void TreeNode::place( TreeCoord& sibOff )
//---------------------------------------
{
    bool vert = (_parent->getDirection() == TreeVertical );
    if( _flags.placed == Placed ) {
        sibOff +=  (vert) ? _descend.w()
                          : _descend.h();
        return;
    }

    if( !readyToPlace() ) {
        return;
    }

    _flags.placed = Placed;

    TreeCoord maxSibW = _sibWidth;
    TreeCoord minSib = (vert) ? _descend.x()
                              : _descend.y();
    TreeCoord maxSib = sibOff;

    sibOff = maxCoord( sibOff, minSib );

    getMinMax( minSib, maxSib );
    maxSibW = maxCoord( maxSibW, maxSib - maxCoord( minSib, sibOff ) );
    TreeCoord oldMaxSibW = maxSibW;
    getFirstNonContend( sibOff, maxSibW );

    (vert) ? _descend.x( maxCoord( _descend.x(), sibOff ) )
           : _descend.y( maxCoord( _descend.y(), sibOff ) );

    TreeCoord x;
    TreeCoord y;
    TreeCoord tryW;
    if( sibOff > minSib || oldMaxSibW > maxSibW ) {
        x = _descend.x() + maxSibW / 2 - _bounding.w() / 2;
        y = _descend.y() + maxSibW / 2 - _bounding.h() / 2;
        tryW = ( vert ? _descend.x() : _descend.y() ) + maxSibW;
    } else {
        x = minSib + maxSibW / 2 - _bounding.w() / 2;
        y = minSib + maxSibW / 2 - _bounding.h() / 2;
        tryW = minSib + maxSibW;
    }

    (vert) ? _descend.w( maxCoord( _descend.w(), tryW - _descend.x() ) )
           : _descend.h( maxCoord( _descend.h(), tryW - _descend.y() ) );

    move( x, y );
    sibOff += maxSibW;

    _descend.w( maxCoord( _descend.w(), _bounding.x() + _bounding.w() - _descend.x() ) );
    _descend.h( maxCoord( _descend.h(), _bounding.y() + _bounding.h() - _descend.y() ) );
}
Example #4
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 = ...

}
Example #5
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 Scene_polyhedron_shortest_path_item::get_as_vertex_point(Scene_polyhedron_shortest_path_item::Face_location& inOutLocation)
{
  size_t maxIndex = 0;
  FT maxCoord(inOutLocation.second[0]);
  
  for (size_t i = 1; i < 3; ++i)
  {
    if (inOutLocation.second[i] > maxCoord)
    {
      maxIndex = i;
      maxCoord = inOutLocation.second[i];
    }
  }
  
  FT coords[3] = { FT(0.0), FT(0.0), FT(0.0), };
  coords[maxIndex] = FT(1.0);
  
  Construct_barycentric_coordinate construct_barycentric_coordinate;
  inOutLocation.second = construct_barycentric_coordinate(coords[0], coords[1], coords[2]);
}
Example #8
0
void TreeNode::setBounding( OutputDevice *dev )
//---------------------------------------------
{
    bool sepIncluded = false;

    if( !_flags.boundSet ) {
        #if DEBUG
        _nm = name();
        #endif

        _flags.boundSet = true;

        int     width;
        int     height;
        char *  nodename = name();

        if( nodename != NULL ) {
            width = dev->getTextExtentX( nodename );
            height = dev->getTextExtentY( nodename );
        } else {
            width = 0;
            height = 0;
        }

        _bounding.w( width + 2 * NodeBuffer );
        _bounding.h( height + 2 * NodeBuffer );

        _sibWidth = 0;

        for( int i = getCount( ParentList ); i > 0; i -= 1 ) {
            TreeNode * node = getNode( ParentList, i - 1 );

            node->setBounding( dev );
            _sibWidth += node->getSibContrib( this, sepIncluded );
        }

        bool vert = (_parent->getDirection() == TreeVertical);
        _sibWidth = maxCoord( _sibWidth, (vert) ? _bounding.w()
                                                : _bounding.h() );
    }
}
Example #9
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;
}
Example #10
0
void TreeNode::getFirstNonContend( TreeCoord& sibOff, TreeCoord& width )
//----------------------------------------------------------------------
{
    if( getLevel() < 0 ) {
        return;
    }

    TreeCoord  origW = width;
    bool vert = _parent->getDirection() == TreeVertical;

    for( int i = 0; i < getCount( FlatList ); i += 1 ) {
        TreeNode * node = getNode( FlatList, i );
        TreeCoord    nodeW = maxCoord( node->_sibWidth,
                                       vert ? node->_descend.w()
                                            : node->_descend.h() );

        if( node != this && node->getLevel() == getLevel() &&
            node->_flags.placed != NotPlaced && node->_flags.enabled > Hidden ) {

            TreeCoord lOff = vert ? node->_descend.x() - sibSep
                            : node->_descend.y() - sibSep;
            TreeCoord mOff = vert ? node->_descend.x() + nodeW + sibSep
                            : node->_descend.y() + nodeW + sibSep;
            if( sibOff + width > lOff && sibOff < mOff ) {
                // contention happening -- try to shrink

                width = maxCoord( _sibWidth,
                                vert ? node->_descend.x() - sibOff - sibSep
                                     : node->_descend.y() - sibOff - sibSep );
            }

            if( sibOff + width > lOff && sibOff < mOff ) {
                // shrinking couldn't fix it -- restore to original size
                // and move past this node.

                width = origW;

                bool done = false;
                for( int childCnt1 = getCount( ChildList );
                     childCnt1 > 0 && !done; childCnt1 -= 1 ) {
                    TreeNode * node1 = getNode( ChildList, childCnt1 - 1 );

                    if( node1->_flags.enabled > Hidden ) {
                        for( int childCnt2 = node->getCount( ChildList );
                             childCnt2 > 0 && !done; childCnt2 -= 1 ) {
                            TreeNode * node2;

                            node2 = node->getNode( ChildList, childCnt2 - 1 );
                            if( node1 == node2 ) {
                                nodeW = node->shrinkToSib();
                                done = true;
                            }
                        }
                    }
                }

                TreeCoord newOff = vert ? node->_descend.x()
                                        : node->_descend.y();
                newOff += nodeW + sibSep;

                sibOff = maxCoord( sibOff, newOff );

                i = -1;     // re-start the loop
            }
        }
    }
}
Example #11
0
void TreeNode::arrangeTree( TreeCoord& sibOff )
//---------------------------------------------
{
    TreeCoord  startSib = sibOff;
    TreeCoord  maxDescend = 0;
    TreeCoord  mySib = sibOff;
    bool       vert  = (_parent->getDirection() == TreeVertical);
    int        i;

    if( !_flags.enabled ) {
        _flags.placed = Placed;
        return;
    }

    _flags.placed = Arranging;
    _flags.arranging = 1;

    // partial results used in getFirstNonContend

    TreeCoord offset = sibOff;
    TreeCoord width = _sibWidth;

    getFirstNonContend( offset, width );
    _descend.x( offset );
    _descend.y( offset );
    _descend.w( width );
    _descend.h( width );

    // scram through and check for simple children (one parent, no kids)
    for( i = 0; i < getCount( ChildList ); i += 1 ) {
        TreeNode * node = getNode( ChildList, i );

        if( node->_flags.placed < Arranging && node->isSimple( ChildList ) ) {
            TreeCoord tmpOff = vert ? _descend.x()
                                    : _descend.y();

            node->arrangeTree( tmpOff );
            tmpOff += sibSep;

            if( getLevel() < 0 || node->getLevel() < 0
                || node->getLevel() == getLevel() + 1 ) {

                sibOff = tmpOff;
            }

            if( node->_flags.enabled > Hidden ) {
                maxDescend = maxCoord( maxDescend,
                            vert ? node->_descend.x() + node->_descend.w()
                                 : node->_descend.y() + node->_descend.h()
                            );
            }
        }
    }

    // do non-simple children

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

        if( node->_flags.placed < Arranging ) {
            TreeCoord tmpOff = vert ? _descend.x()
                                    : _descend.y();

            node->arrangeTree( tmpOff );

            tmpOff += sibSep;
            if( getLevel() < 0 || node->getLevel() < 0 ||
                 node->getLevel() == getLevel() + 1 ) {

                sibOff = tmpOff;
            }

            if( node->_flags.enabled > Hidden ) {
                maxDescend = maxCoord( maxDescend,
                            vert ? node->_descend.x() + node->_descend.w()
                                 : node->_descend.y() + node->_descend.h()
                            );
            }
        }
    }

    place( mySib );

    // do simple parents

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

        sibOff = vert ? _descend.x() : _descend.y();

        if( node->isSimple( ParentList ) && node->_flags.placed < Arranging ) {
            node->arrangeTree( sibOff );

            if( node->_flags.enabled > Hidden ) {
                maxDescend = maxCoord( maxDescend,
                            vert ? node->_descend.x() + node->_descend.w()
                                 : node->_descend.y() + node->_descend.h()
                            );
            }
        }
    }

    // do non-simple parents

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

        sibOff = vert ? _descend.x() : _descend.y();

        if( node->_flags.placed < Arranging ) {
            node->arrangeTree( sibOff );

            if( node->_flags.enabled > Hidden ) {
                maxDescend = maxCoord( maxDescend,
                            vert ? node->_descend.x() + node->_descend.w()
                                 : node->_descend.y() + node->_descend.h()
                            );
            }
        }
    }

    if( _flags.placed != Placed ) {
        _flags.placed = PartiallyPlaced;
    } else {
        vert ? _descend.w( maxCoord( _descend.w(), maxDescend - _descend.x() ) )
             : _descend.h( maxCoord( _descend.h(), maxDescend - _descend.y() ) );
    }

    sibOff = maxCoord( sibOff, vert ? _descend.x() + _descend.w()
                                  : _descend.y() + _descend.h() );

    _flags.arranging = 0;
}
Example #12
0
 void pop_back(){
   minCoord().pop_back();
   maxCoord().pop_back();
   _partNumber.pop_back();
 }
Example #13
0
 void push_back(const FormulaPtr& b,const FormulaPtr& e, unsigned int f){
   minCoord().push_back(b);
   maxCoord().push_back(e);
   _partNumber.push_back(f);
 }
Example #14
0
 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

}
Example #16
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
		}