コード例 #1
0
GridField<T>::GridField(const GridMapping &m, Extrapolation<T> *extrapolation):GridMapping(m),_extrapolation(nullptr),_interpolation(nullptr),_extrapolate(true){

	//Allokera data-array
	_data = new T[cellCount()];
	for (int i = 0; i < cellCount(); i++) _data[i] = T(0);

	//Extra/Interpolation
	setInterpolation(Interpolation<T>::defaultInterpolation());
	setExtrapolation(extrapolation);
}
コード例 #2
0
GridField<T>::GridField(int xdim,int ydim, int zdim, double size, Extrapolation<T> *extrapolation):GridMapping(xdim,ydim,zdim,size),_extrapolation(nullptr),_interpolation(nullptr),_extrapolate(true){

	//Allokera data-array
	_data = new T[cellCount()];
	for (int i = 0; i < cellCount(); i++) _data[i] = T();

	//Extra/Interpolation
	setInterpolation(Interpolation<T>::defaultInterpolation());
	setExtrapolation(extrapolation);
}
コード例 #3
0
ファイル: abstractgrid.cpp プロジェクト: KDE/knetwalk
void AbstractGrid::createGrid()
{
    // add a random server
    server_index = qrand() % (cellCount());

    // number of cells that aren't free
    int notFreeCells = 0;
    const int minimumNumCells = cellCount() * minCellRatio;
    // retries until the minimum number of cells is big enough
    while (notFreeCells < minimumNumCells) {

        for (int i = 0; i < cellCount(); ++i) {
            m_cells[i]->makeEmpty();
        }
        m_cells[server_index]->setServer(true);

        QList<uint> list;
        list.append(server_index);
        if (qrand() % 2) addRandomCable(list);

        // add some random cables...
        // the list empties if there aren't many free cells left
        // (because of addRandomCable() not doing anything)
        while (!list.isEmpty()) {
            if (qrand() % 2) {
                addRandomCable(list);
                if (qrand() % 2) addRandomCable(list);
                list.erase(list.begin());
            }
            else {
                list.append(list.first());
                list.erase(list.begin());
            }
        }

        // count not empty cells
        notFreeCells = 0;
        for (int i = 0; i < cellCount(); ++i) {
            if (m_cells[i]->cables() != None) ++notFreeCells;
        }
    }
}
コード例 #4
0
GridField<T>& GridField<T>::operator=(const GridField<T> &g){
	if (this != &g) {

		//Allokera data-array
		if(g.cellCount() != cellCount()){
			delete _data;
			_data = new T[g.cellCount()];
		}
		std::copy(g._data,g._data+g.cellCount(), _data);

		setInterpolation(g._interpolation);
		setExtrapolation(g._extrapolation);
	}

	return *this;
}
コード例 #5
0
ファイル: RigGridBase.cpp プロジェクト: magnesj/ResInsight
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
cvf::BoundingBox RigGridBase::boundingBox()
{
    if (!m_boundingBox.isValid())
    {
        cvf::Vec3d cornerVerts[8];

        for (size_t i = 0; i < cellCount(); i++)
        {
            cellCornerVertices(i, cornerVerts);

            for (size_t j = 0; j < 8; j++)
            {
                m_boundingBox.add(cornerVerts[j]);
            }
        }
    }
    
    return m_boundingBox;
}
コード例 #6
0
ファイル: RigGridBase.cpp プロジェクト: magnesj/ResInsight
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RigGridBase::ijkFromCellIndex(size_t cellIndex, size_t* i, size_t* j, size_t* k) const
{
    CVF_TIGHT_ASSERT(cellIndex < cellCount());

    size_t index = cellIndex;

    if (cellCountI() <= 0 || cellCountJ() <= 0)
    {
        return false;
    }

    *k      = index/(cellCountI()*cellCountJ());
    index   -= (*k)*(cellCountI()*cellCountJ());
    *j      = index/cellCountI();
    index   -= (*j)*cellCountI();
    *i      = index;


    return true;
}
コード例 #7
0
ファイル: abstractgrid.cpp プロジェクト: KDE/knetwalk
void AbstractGrid::initializeGrid(uint width, uint height, Wrapping wrapping)
{
    if ((width * height) != (m_width * m_height)) {
        qDeleteAll(m_cells);
        m_cells.clear();

        for (uint index = 0; index < width*height; ++index) {
            m_cells.append(newCell(index));
        }
    }

    m_width = width;
    m_height = height;
    m_isWrapped = wrapping;

    createGrid();

    while(hasUnneededCables() || solutionCount() != 1) {
        // the grid is invalid: create a new one
        createGrid();
    }

    m_minimumMoves = 0;
    const int shuffleLimit = cellCount() * minCellRatio;
    QList<int> notShuffledCells;
    for (int i = 0; i < cellCount(); ++i)
        notShuffledCells.append(i);

    // select a random cell that is not yet shuffled
    // rotate such that initial and final states are not same
    // repeat above two steps until minimum moves equal to shuffle limit
    while(m_minimumMoves < shuffleLimit)
    {
        // selecting a random index
        int index = qrand() % notShuffledCells.count();
        int cellNo = notShuffledCells[index];
        // removing the selected index so that it must not be used again
        notShuffledCells.removeAt(index);
        AbstractCell *cell = m_cells[cellNo];
        Directions dir = cell->cables();

        // excludes None(Empty cell)
        if (dir == None) {
            continue;
        }
        // if straight line rotate once
        // cant rotate twice(it will be back on its initial state)
        else if ((dir == (Up | Down)) || (dir == (Left | Right))) {
            m_minimumMoves += 1;
            cell->rotateClockwise();
        }
        // for every other case rotate 1..3 times
        else {
            int rotation = qrand() % 3 + 1; // 1..3
            // cant rotate twice when m_minimumMoves == shuffleLimit - 1
            if (m_minimumMoves == shuffleLimit - 1 && rotation == 2){
                rotation = (qrand() % 2)? 1 : 3; // 1 or 3
            }
            m_minimumMoves += (rotation == 3) ? 1 : rotation;
            while(rotation--) {
                cell->rotateClockwise();
            }
        }
    }

    updateConnections();
}
コード例 #8
0
void GridField<T>::setAll(T val){
	for (int i = 0; i < cellCount(); i++) _data[i] = val;
}
コード例 #9
0
bool GridField<T>::isUndefined(int i) const{
	return i < 0 || i >= cellCount();
}
コード例 #10
0
ファイル: FakeMDEventData.cpp プロジェクト: mkoennecke/mantid
void FakeMDEventData::addFakeRegularData(
    const std::vector<double> &params,
    typename MDEventWorkspace<MDE, nd>::sptr ws) {
  // the parameters for regular distribution of events over the box
  std::vector<double> startPoint(nd), delta(nd);
  std::vector<size_t> indexMax(nd);
  size_t gridSize(0);

  // bool RandomizeSignal = getProperty("RandomizeSignal");

  size_t num = size_t(params[0]);
  if (num == 0)
    throw std::invalid_argument(
        " number of distributed events can not be equal to 0");

  Progress prog(this, 0.0, 1.0, 100);
  size_t progIncrement = num / 100;
  if (progIncrement == 0)
    progIncrement = 1;

  // Inserter to help choose the correct event type
  auto eventHelper =
      MDEvents::MDEventInserter<typename MDEventWorkspace<MDE, nd>::sptr>(ws);

  gridSize = 1;
  for (size_t d = 0; d < nd; ++d) {
    double min = ws->getDimension(d)->getMinimum();
    double max = ws->getDimension(d)->getMaximum();
    double shift = params[d * 2 + 1];
    double step = params[d * 2 + 2];
    if (shift < 0)
      shift = 0;
    if (shift >= step)
      shift = step * (1 - FLT_EPSILON);

    startPoint[d] = min + shift;
    if ((startPoint[d] < min) || (startPoint[d] >= max))
      throw std::invalid_argument("RegularData: starting point must be within "
                                  "the box for all dimensions.");

    if (step <= 0)
      throw(std::invalid_argument(
          "Step of the regular grid is less or equal to 0"));

    indexMax[d] = size_t((max - min) / step);
    if (indexMax[d] == 0)
      indexMax[d] = 1;
    // deal with round-off errors
    while ((startPoint[d] + double(indexMax[d] - 1) * step) >= max)
      step *= (1 - FLT_EPSILON);

    delta[d] = step;

    gridSize *= indexMax[d];
  }
  // Create all the requested events
  std::vector<size_t> indexes;
  size_t cellCount(0);
  for (size_t i = 0; i < num; ++i) {
    coord_t centers[nd];

    Kernel::Utils::getIndicesFromLinearIndex(cellCount, indexMax, indexes);
    ++cellCount;
    if (cellCount >= gridSize)
      cellCount = 0;

    for (size_t d = 0; d < nd; d++) {
      centers[d] = coord_t(startPoint[d] + delta[d] * double(indexes[d]));
    }

    // Default or randomized error/signal
    float signal = 1.0;
    float errorSquared = 1.0;
    // if (RandomizeSignal)
    //{
    //  signal = float(0.5 + genUnit());
    //  errorSquared = float(0.5 + genUnit());
    //}

    // Create and add the event.
    eventHelper.insertMDEvent(signal, errorSquared, 1, pickDetectorID(),
                              centers); // 1 = run number
    // Progress report
    if ((i % progIncrement) == 0)
      prog.report();
  }
}