コード例 #1
0
ファイル: transpose.hpp プロジェクト: 9prady9/arrayfire
void transpose(Param<T> output, CParam<T> input) {
    const dim4 odims    = output.dims();
    const dim4 ostrides = output.strides();
    const dim4 istrides = input.strides();

    T *out            = output.get();
    T const *const in = input.get();

    for (dim_t l = 0; l < odims[3]; ++l) {
        for (dim_t k = 0; k < odims[2]; ++k) {
            // Outermost loop handles batch mode
            // if input has no data along third dimension
            // this loop runs only once
            for (dim_t j = 0; j < odims[1]; ++j) {
                for (dim_t i = 0; i < odims[0]; ++i) {
                    // calculate array indices based on offsets and strides
                    // the helper getIdx takes care of indices
                    const dim_t inIdx  = getIdx(istrides, j, i, k, l);
                    const dim_t outIdx = getIdx(ostrides, i, j, k, l);
                    if (conjugate)
                        out[outIdx] = getConjugate(in[inIdx]);
                    else
                        out[outIdx] = in[inIdx];
                }
            }
            // outData and inData pointers doesn't need to be
            // offset as the getIdx function is taking care
            // of the batch parameter
        }
    }
}
コード例 #2
0
void diff2(Param<T> out, CParam<T> in, int const dim)
{
    af::dim4 dims = out.dims();
    // Bool for dimension
    bool is_dim0 = dim == 0;
    bool is_dim1 = dim == 1;
    bool is_dim2 = dim == 2;
    bool is_dim3 = dim == 3;

    T const * const inPtr = in.get();
    T * outPtr = out.get();

    // TODO: Improve this
    for(dim_t l = 0; l < dims[3]; l++) {
        for(dim_t k = 0; k < dims[2]; k++) {
            for(dim_t j = 0; j < dims[1]; j++) {
                for(dim_t i = 0; i < dims[0]; i++) {
                    // Operation: out[index] = in[index + 1 * dim_size] - in[index]
                    int idx = getIdx(in.strides(), i, j, k, l);
                    int jdx = getIdx(in.strides(),
                            i + is_dim0, j + is_dim1,
                            k + is_dim2, l + is_dim3);
                    int kdx = getIdx(in.strides(),
                            i + 2 * is_dim0, j + 2 * is_dim1,
                            k + 2 * is_dim2, l + 2 * is_dim3);
                    int odx = getIdx(out.strides(), i, j, k, l);
                    outPtr[odx] = inPtr[kdx] + inPtr[idx] - inPtr[jdx] - inPtr[jdx];
                }
            }
        }
    }
}
コード例 #3
0
ファイル: ZAdaptiveNormals.cpp プロジェクト: Cerarus/v4r
/**
 * GetIndices
 */
void ZAdaptiveNormals::getIndices(const v4r::DataMatrix2D<Eigen::Vector3f> &cloud, int u, int v, int kernel, std::vector<int> &indices)
{
  int idx;
  const Eigen::Vector3f &pt = cloud.data[getIdx(u,v)]; 

  for (int vkernel=0-kernel; vkernel<=kernel; vkernel++) {
    for (int ukernel=0-kernel; ukernel<=kernel; ukernel++) {
      int y = v + vkernel;
      int x = u + ukernel;
      
      float center_dist = sqrt(vkernel*vkernel + ukernel*ukernel);
      if (x>0 && y>0 && x<width && y<height) {
        idx = getIdx(x,y);
        const Eigen::Vector3f &pt1 = cloud.data[idx];
        if(!std::isnan(pt1[2])) {
          float new_sqr_radius = sqr_radius;
          if(param.adaptive) {
            float val = param.kappa * center_dist * pt1[2] + param.d;
            new_sqr_radius = val*val;
          }
        
          if ((pt-pt1).squaredNorm() < new_sqr_radius)
            indices.push_back(idx);
        }
      }
    }
  }
}
コード例 #4
0
ファイル: morph.hpp プロジェクト: Brainiarc7/arrayfire
void morph3d(Array<T> out, Array<T> const in, Array<T> const mask)
{
    const af::dim4 dims     = in.dims();
    const af::dim4 window   = mask.dims();
    const dim_t R0      = window[0]/2;
    const dim_t R1      = window[1]/2;
    const dim_t R2      = window[2]/2;
    const af::dim4 istrides = in.strides();
    const af::dim4 fstrides = mask.strides();
    const dim_t bCount  = dims[3];
    const af::dim4 ostrides = out.strides();
    T* outData          = out.get();
    const T*   inData   = in.get();
    const T*   filter   = mask.get();

    for(dim_t batchId=0; batchId<bCount; ++batchId) {
        // either channels or batch is handled by outer most loop
        for(dim_t k=0; k<dims[2]; ++k) {
            // k steps along 3rd dimension
            for(dim_t j=0; j<dims[1]; ++j) {
                // j steps along 2nd dimension
                for(dim_t i=0; i<dims[0]; ++i) {
                    // i steps along 1st dimension
                    T filterResult = inData[ getIdx(istrides, i, j, k) ];

                    // wk, wj,wi steps along 2nd & 1st dimensions of filter window respectively
                    for(dim_t wk=0; wk<window[2]; wk++) {
                        for(dim_t wj=0; wj<window[1]; wj++) {
                            for(dim_t wi=0; wi<window[0]; wi++) {

                                dim_t offk = k+wk-R2;
                                dim_t offj = j+wj-R1;
                                dim_t offi = i+wi-R0;

                                T maskValue = filter[ getIdx(fstrides, wi, wj, wk) ];

                                if ((maskValue > (T)0) && offi>=0 && offj>=0 && offk>=0 &&
                                        offi<dims[0] && offj<dims[1] && offk<dims[2]) {

                                    T inValue   = inData[ getIdx(istrides, offi, offj, offk) ];

                                    if (IsDilation)
                                        filterResult = std::max(filterResult, inValue);
                                    else
                                        filterResult = std::min(filterResult, inValue);
                                }

                            } // window 1st dimension loop ends here
                        }  // window 1st dimension loop ends here
                    }// filter window loop ends here

                    outData[ getIdx(ostrides, i, j, k) ] = filterResult;
                } //1st dimension loop ends here
            } // 2nd dimension loop ends here
        } // 3rd dimension loop ends here
        // next iteration will be next batch if any
        outData += ostrides[3];
        inData  += istrides[3];
    }
}
コード例 #5
0
ファイル: transpose.hpp プロジェクト: 9prady9/arrayfire
void transpose_inplace(Param<T> input) {
    const dim4 idims    = input.dims();
    const dim4 istrides = input.strides();

    T *in = input.get();

    for (dim_t l = 0; l < idims[3]; ++l) {
        for (dim_t k = 0; k < idims[2]; ++k) {
            // Outermost loop handles batch mode
            // if input has no data along third dimension
            // this loop runs only once
            //
            // Run only bottom triangle. std::swap swaps with upper triangle
            for (dim_t j = 0; j < idims[1]; ++j) {
                for (dim_t i = j + 1; i < idims[0]; ++i) {
                    // calculate array indices based on offsets and strides
                    // the helper getIdx takes care of indices
                    const dim_t iIdx = getIdx(istrides, j, i, k, l);
                    const dim_t oIdx = getIdx(istrides, i, j, k, l);
                    if (conjugate) {
                        in[iIdx] = getConjugate(in[iIdx]);
                        in[oIdx] = getConjugate(in[oIdx]);
                        std::swap(in[iIdx], in[oIdx]);
                    } else {
                        std::swap(in[iIdx], in[oIdx]);
                    }
                }
            }
        }
    }
}
コード例 #6
0
void bilateral(Param<OutT> out, CParam<InT> in, float const s_sigma, float const c_sigma)
{
    af::dim4 const dims     = in.dims();
    af::dim4 const istrides = in.strides();
    af::dim4 const ostrides = out.strides();

    // clamp spatical and chromatic sigma's
    float space_       = std::min(11.5f, std::max(s_sigma, 0.f));
    float color_       = std::max(c_sigma, 0.f);
    dim_t const radius = std::max((dim_t)(space_ * 1.5f), (dim_t)1);
    float const svar   = space_*space_;
    float const cvar   = color_*color_;

    for(dim_t b3=0; b3<dims[3]; ++b3) {

        OutT *outData = out.get() + b3 * ostrides[3];
        InT const * inData  = in.get() + b3 * istrides[3];

        // b3 for loop handles following batch configurations
        //  - gfor
        //  - input based batch
        //      - when input is 4d array for color images
        for(dim_t b2=0; b2<dims[2]; ++b2) {
            // b2 for loop handles following batch configurations
            //  - channels
            //  - input based batch
            //      - when input is 3d array for grayscale images
            for(dim_t j=0; j<dims[1]; ++j) {
                // j steps along 2nd dimension
                for(dim_t i=0; i<dims[0]; ++i) {
                    // i steps along 1st dimension
                    OutT norm = 0.0;
                    OutT res  = 0.0;
                    OutT const center = (OutT)inData[getIdx(istrides, i, j)];
                    for(dim_t wj=-radius; wj<=radius; ++wj) {
                        // clamps offsets
                        dim_t tj = clamp(j+wj, dim_t(0), dims[1]-1);
                        for(dim_t wi=-radius; wi<=radius; ++wi) {
                            // clamps offsets
                            dim_t ti = clamp(i+wi, dim_t(0), dims[0]-1);
                            // proceed
                            OutT const val= (OutT)inData[getIdx(istrides, ti, tj)];
                            OutT const gauss_space = (wi*wi+wj*wj)/(-2.0*svar);
                            OutT const gauss_range = ((center-val)*(center-val))/(-2.0*cvar);
                            OutT const weight = std::exp(gauss_space+gauss_range);
                            norm += weight;
                            res += val*weight;
                        }
                    } // filter loop ends here

                    outData[getIdx(ostrides, i, j)] = res/norm;
                } //1st dimension loop ends here
            } //2nd dimension loop ends here
            outData += ostrides[2];
            inData  += istrides[2];
        }
    }
}
コード例 #7
0
HRESULT CaPerfDataWriter::updateSectionHdr(caperf_section_type_t section, gtUInt64 startOffset, gtUInt64 size)
{
    struct caperf_section_hdr hdr;
    memset((void*)&hdr, 0, sizeof(caperf_section_hdr));

    int ret = S_OK;
    gtUInt32 idx = getIdx(section);

    if (CAPERF_MAX_SECTIONS > idx)
    {
        lseek(m_fd, m_sectionHdrOffsets[idx], SEEK_SET);
        ssize_t rc = read(m_fd, &hdr, sizeof(hdr));
        GT_ASSERT(rc != -1);

        hdr.offset = startOffset;
        hdr.size = size;

        lseek(m_fd, m_sectionHdrOffsets[idx], SEEK_SET);

        ssize_t ret = write(m_fd, (const void*)&hdr, sizeof(hdr));

        if (ret != sizeof(hdr))
        {
            OS_OUTPUT_DEBUG_LOG(L"Error while updating section header", OS_DEBUG_LOG_ERROR);
            ret = E_FAIL;
        }
    }

    return ret;
}
コード例 #8
0
// Debug helper method: print the contents of the abtract data type to the serial console
void SensorBuffer::PrintContentsDEBUG() {
    Serial.println ("-----------------------------------");
    Serial.println ("SensorBuffer: ");

    Serial.print ("Size: ");
    Serial.println (size);

    Serial.print ("validData: ");
    Serial.println (validData);

    Serial.print ("ringReadIdx: ");
    Serial.println (ringReadIdx);

    Serial.print ("ringWriteIdx: ");
    Serial.println (ringWriteIdx);

    for (int32_t i=0; i<size; i++) {
        Serial.print ("  [");
        Serial.print (i);
        Serial.print ("]: ");
        Serial.print ( getIdx(i) );

        // Display 10 values per line
        if ((i % 10) == 9) {
            Serial.println ("");
        }
    }
    Serial.println ("");
    Serial.println ("-----------------------------------");

}
コード例 #9
0
ファイル: CCTableView.cpp プロジェクト: TheWindShan/HYFish
void TableView::insertCellAtIndex(ssize_t idx)
{
    if (idx == CC_INVALID_INDEX)
    {
        return;
    }

    long countOfItems = _dataSource->numberOfCellsInTableView(this);
    if (0 == countOfItems || idx > countOfItems-1)
    {
        return;
    }

    long newIdx = 0;

    auto cell = cellAtIndex(idx);
    if (cell)
    {
        newIdx = _cellsUsed.getIndex(cell);
        // Move all cells behind the inserted position
        for (long i = newIdx; i < _cellsUsed.size(); i++)
        {
            cell = _cellsUsed.at(i);
            this->_setIndexForCell(cell->getIdx()+1, cell);
        }
    }

    //insert a new cell
    cell = _dataSource->tableCellAtIndex(this, idx);
    this->_setIndexForCell(idx, cell);
    this->_addCellIfNecessary(cell);

    this->_updateCellPositions();
    this->_updateContentSize();
}
コード例 #10
0
ファイル: Ground.cpp プロジェクト: tcagame/HoneyMiner
void Ground::setType( int mx, int my, GROUND_CHIP_TYPE type ) {
	if ( mx < 0 || mx >= _width ||
		 my < 0 || my >= _height ) {
			return;
	}
	_array_type[ getIdx( mx, my ) ] = type;
}
コード例 #11
0
int main(){
	int i, j, N;
	freopen("t.in", "r", stdin);
	freopen("ans.out", "w", stdout);
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		int ans = 0, idx = 0;
		char res[100] = {'0'};
		scanf("%s%s%s", alien, src, dest);
		int srcLen = strlen(src);
		int destLen = strlen(dest);
		int alienLen = strlen(alien);

		for(j = 0; j < alienLen; j++)
			ans = getIdx(alien[j]) + ans * srcLen;
		
		while(ans > 0){
			res[idx++] = dest[ans % destLen];
			ans /= destLen;
		}
		printf("Case #%d: ", i+1);
		for(j = idx -1; j >= 0; j--)
			printf("%c", res[j]);
		printf("\n");
	}
}
コード例 #12
0
bool ExtManager::enable(const char* name, bool flag /* =true */)
{
    assert(name);

    int idx = getIdx(name);
    if (idx >= 0) isEnabled[idx] = flag;
    return idx >= 0;
}
コード例 #13
0
ファイル: Ground.cpp プロジェクト: tcagame/HoneyMiner
GROUND_CHIP_TYPE Ground::getType( int mx, int my ) const {
	if ( mx < 0 || mx >= _width ||
		 my < 0 || my >= _height ) {
			return GROUND_CHIP_TYPE_RIVER;
	}
	GROUND_CHIP_TYPE chip = _array_type[ getIdx( mx, my ) ];

	return chip;
}
コード例 #14
0
ファイル: concurrent_hash_set.cpp プロジェクト: webserg/cpp
int concurrent_hash_set::contains(int d)
{
	lock_guard<mutex> guard(mutex_guard);
	for (auto e : elems[getIdx(d)])
	{
		if (e == d) return 1;
	}
	return 0;
}
コード例 #15
0
ファイル: bns copy 3.c プロジェクト: DavidGogh/CO-FP-2016
void cross2DConv()
{
	int i, j, k, l;
	int filIdx, inIdx;
	int weight, kernLen;
	int rgb[3], idx[3];
	int filterPix;
	Pixel *pixelPtr;

	kernLen = kernSize/2;
	for(inIdx = 0; inIdx < numInput; inIdx++){
			for(filIdx = 0; filIdx < numFilter; filIdx++){
				for(i = 0; i < imgWidth; i++){
					for(j = 0; j < imgHeight; j++){

								rgb[0] = 0; rgb[1] = 0; rgb[2] = 0;
								weight = weights[filIdx];
								for(k = 0; k < kernSize; k++){
									for(l = 0; l < kernSize; l++){
										idx[0] = getIdx(j, i - j);
										idx[1] = idx[0]%imgWidth - kernLen + l;
										idx[2] = idx[0]/imgWidth - kernLen + k;
										filterPix=filters[filIdx][k][l];
										if((idx[1] >= 0) && (idx[2] >= 0) && 
											 (idx[1] < imgWidth) && (idx[2] < imgHeight)){
											pixelPtr = (Pixel *) &data[inIdx][getIdx(idx[2], idx[1])
																												* sizeof(Pixel)];
											rgb[0] += filterPix * (pixelPtr->R - 0);
											rgb[1] += filterPix * (pixelPtr->G - 0);
											rgb[2] += filterPix * (pixelPtr->B - 0);
										}                               
										else                            
											weight -= filterPix;
									}
								}		
								checkPixelValue(rgb, weight);
								setPixel(results[filIdx][inIdx], idx[0], rgb);
					}
				}
			}
	}

}
コード例 #16
0
ファイル: cells.cpp プロジェクト: Aieener/HRE
Square& Cells::getSquare( int x, int y) const
{
	if (x >= N0 || y >= N1)
	{
		throw EXC_INVALID_DESC;
	}

	int idx = getIdx(x,y);
	// cout << idx<<endl;
	return arr[idx];
}
コード例 #17
0
ファイル: SseSimulator.cpp プロジェクト: jonr925/SonATA
// Return the specified parameter as an int
int
passThruCfg::getInt(const char * pName, int cmd)
{
    string n;
    n="";
    int idx = getIdx(pName, cmd);
    if (paramsTable[idx].val == n)
        return atoi(paramsTable[idx].dflt);
    else
        return atoi(paramsTable[idx].val.c_str());
};
コード例 #18
0
ファイル: diff.cpp プロジェクト: PierreBizouard/arrayfire
    Array<T>  diff2(const Array<T> &in, const int dim)
    {
        // Bool for dimension
        bool is_dim0 = dim == 0;
        bool is_dim1 = dim == 1;
        bool is_dim2 = dim == 2;
        bool is_dim3 = dim == 3;

        // Decrement dimension of select dimension
        af::dim4 dims = in.dims();
        dims[dim] -= 2;

        // Create output placeholder
        Array<T> outArray = createValueArray(dims, (T)0);

        // Get pointers to raw data
        const T *inPtr = in.get();
              T *outPtr = outArray.get();

        // TODO: Improve this
        for(dim_t l = 0; l < dims[3]; l++) {
            for(dim_t k = 0; k < dims[2]; k++) {
                for(dim_t j = 0; j < dims[1]; j++) {
                    for(dim_t i = 0; i < dims[0]; i++) {
                        // Operation: out[index] = in[index + 1 * dim_size] - in[index]
                        int idx = getIdx(in.strides(), in.offsets(), i, j, k, l);
                        int jdx = getIdx(in.strides(), in.offsets(),
                                         i + is_dim0, j + is_dim1,
                                         k + is_dim2, l + is_dim3);
                        int kdx = getIdx(in.strides(), in.offsets(),
                                         i + 2 * is_dim0, j + 2 * is_dim1,
                                         k + 2 * is_dim2, l + 2 * is_dim3);
                        int odx = getIdx(outArray.strides(), outArray.offsets(), i, j, k, l);
                        outPtr[odx] = inPtr[kdx] + inPtr[idx] - inPtr[jdx] - inPtr[jdx];
                    }
                }
            }
        }

        return outArray;
    }
コード例 #19
0
ファイル: PlayerItem.cpp プロジェクト: AIRIA/CreazyBomber
void PlayerItem::update(float delta)
{
    auto rect = getBoundingBox();
    rect.size = Size(TILE_WIDTH,TILE_HEIGHT/2);
    auto playerRect = GameManager::getInstance()->getPlayer()->getBoundingBox();
    if(playerRect.intersectsRect(rect))
    {
        auto manager = GameManager::getInstance();
        auto data = PlayerInfoParam::create();
        data->setType(getItemType().itemType);
        switch (data->getType()) {
            case PlayerInfoParam::kTypeBomb:
                manager->setBombNum(manager->getBombNum()+1);
                data->setValue(manager->getBombNum());
                Util::playEffect(SOUND_ITEM_GET_BOMB);
                break;
            case PlayerInfoParam::kTypeCoin:
                if(getIdx()==0)
                {
                    __userDefault->setIntegerForKey(KEY_COIN_NUM, __userDefault->getIntegerForKey(KEY_COIN_NUM)+50);
                    Util::playEffect(SOUND_ITEM_GET_LITTLE_COIN);
                }else{
                    __userDefault->setIntegerForKey(KEY_COIN_NUM, __userDefault->getIntegerForKey(KEY_COIN_NUM)+100);
                    Util::playEffect(SOUND_ITEM_GET_BIG_COIN);
                }
                data->setValue(__userDefault->getIntegerForKey(KEY_COIN_NUM));
                break;
            case PlayerInfoParam::kTypeShoe:
                Util::playEffect(SOUND_ITEM_GET_SHOE);
                manager->setShoe(manager->getShoe()+1);
                data->setValue(manager->getShoe());
                
                if(_speedUp==false)
                {
                    manager->setSpeed(manager->getSpeed()*1.3f);
                    manager->getPlayer()->setSpeed(manager->getPlayer()->getSpeed()*1.3f);
                    checkShoeNum();
                }
                
                break;
            case PlayerInfoParam::kTypePower:
                Util::playEffect(SOUND_ITEM_GET_POWER);
                manager->setBombPower(manager->getBombPower()+1);
                data->setValue(manager->getBombPower());
                break;
            default:
                break;
        }
        NotificationCenter::getInstance()->postNotification(UPDATE_PLAYER_INFO,data);
        removeFromParent();
    }
}
コード例 #20
0
ファイル: SseSimulator.cpp プロジェクト: jonr925/SonATA
//
// Read the next command from the configuration file.
// Validate the parameters assoicated with the command.
// Update the val in the paramsTable.
//
int
passThruCfg::getNxtCmd()
{


    // Read the next command, its activity ID and
    // parameters.  Validate the parameters and
    // save the associated values
    string pName, pVal;
    int idx;


    if (!nxtCmd) {
        thisCmd = getCmd();
        thisActId = getActId();

    } else if (nxtCmd == -1) {
        // nothing left to read in the file.
        printf("Finished reading '%s' \n",fName.c_str());
        return 0;
    } else {
        thisCmd = nxtCmd;
        thisActId = nxtActId;
        nxtCmd = nxtActId = 0;
    }
    while (!nxtCmd) {
        getNextLine(&pName,&pVal);


        // The file contains no more data. Return the
        // previously read cmd and activity
        if (configFile.eof()) {
            nxtCmd = -1;
            continue;
        }


        if (pName == "Command") {
            nxtCmd = atoi(pVal.c_str());
            nxtActId = getActId();
           break;
        }

        idx = getIdx(pName,thisCmd);
        paramsTable[idx].val = pVal;

    }
    return (thisCmd);
}
コード例 #21
0
ファイル: p124.cpp プロジェクト: yogeshg/small-projects
TreeNode* makeTree(TreeNode* tree, std::string treeStr, char delim=' ') {
    std::stringstream ss( treeStr );
    std::string nodeStr;
    int idx = 0;
    while(std::getline(ss, nodeStr, delim)) {
        try {
            const auto nodeVal = std::stoi( nodeStr );
            getIdx(tree, idx)->val = nodeVal;
        } catch( std::invalid_argument ) {
        }
        treeToCout( tree );
        std::cout << "\n";
        ++idx;
    }
    return NULL;
}
コード例 #22
0
ファイル: environment.cpp プロジェクト: thanhpx04/project
void Environment::getNeighbors(int idx, int *neigh, int &size){

    int py = idx % (x * y) / x;
    int px = idx % (x * y) % x;

    for(int n = -1; n <= 1; n++){
        if(n + py < 0 || n + py >= y)
            continue;
        for(int m = -1; m <= 1; m++){
            if(m + px < 0 || m + px >=x)
                continue;
            if(m == 0 && n == 0)
                continue;
            neigh[size++] = getIdx(m + px, n + py);
        }

    }

}
コード例 #23
0
void my_free(void* ptr)
{
    // get the address of the metadata
    char *p = (char*) ptr;
    // get the address of the current 
    metadata_t *currBlock = (metadata_t*)(p - sizeof(metadata_t));
    // detect double free
    if (!currBlock->in_use) {
        ERRNO = DOUBLE_FREE_DETECTED;
        return;
    } else {
        currBlock->in_use = 0;
    }
    // recursively merge blocks if possible
    int idx = getIdx(currBlock->size);
    mergeBlock(idx, currBlock);

    // set the error code
    ERRNO = NO_ERROR;
}
コード例 #24
0
ファイル: ZAdaptiveNormals.cpp プロジェクト: Cerarus/v4r
/**
 * EstimateNormals
 */
void ZAdaptiveNormals::estimateNormals(const v4r::DataMatrix2D<Eigen::Vector3f> &cloud, v4r::DataMatrix2D<Eigen::Vector3f> &normals)
{
  EIGEN_ALIGN16 Eigen::Matrix3f eigen_vectors;
  std::vector< int > indices;

  #pragma omp parallel for private(eigen_vectors,indices)
  for (int v=0; v<height; v++) {
    for (int u=0; u<width; u++) {
      indices.clear();
      int idx = getIdx(u,v);
      const Eigen::Vector3f &pt = cloud.data[idx];
      Eigen::Vector3f &n = normals.data[idx];
      if(!std::isnan(pt[0]) && !std::isnan(pt[1]) && !std::isnan(pt[2])) {      
        if(param.adaptive) {
          int dist = (int) (pt[2]*2); // *2 => every 0.5 meter another kernel radius
          getIndices(cloud, u,v, param.kernel_radius[dist], indices);
        }
        else
          getIndices(cloud, u,v, param.kernel, indices);
      }

      if (indices.size()<4) {
        n[0] = NaN;
        continue;
      }

      /* curvature= */ computeNormal(cloud, indices, eigen_vectors);

      n[0] = eigen_vectors (0,0);
      n[1] = eigen_vectors (1,0);
      n[2] = eigen_vectors (2,0);


      if (n.dot(pt) > 0) {
        n *= -1;
        //n.getNormalVector4fMap()[3] = 0;
        //n.getNormalVector4fMap()[3] = -1 * n.getNormalVector4fMap().dot(pt.getVector4fMap());
      }
    }
  }
}
コード例 #25
0
ファイル: NiuNiuRoom.cpp プロジェクト: BillXu/NewProject
bool CNiuNiuRoom::onMessage( Json::Value& prealMsg ,uint16_t nMsgType, eMsgPort eSenderPort , uint32_t nSessionID  )
{
	if ( ISitableRoom::onMessage(prealMsg,nMsgType,eSenderPort,nSessionID) )
	{
		return true ;
	}

	switch ( nMsgType )
	{
	case MSG_REQ_RESIGN_BANKER:
		{
			auto pPlayer = getSitdownPlayerBySessionID(nSessionID) ;
			uint8_t nRet = 0 ;
			do
			{
				if ( !pPlayer || pPlayer->getIdx() != getBankerIdx() )
				{
					nRet = 1 ;
					break; 
				}

				if ( 2 != m_nResignBankerCtrl )
				{
					nRet = 2 ;
					break ;
				}

				m_isWillManualLeaveBanker = true ;
			}
			while(0);
			Json::Value jsmsgBack ;
			jsmsgBack["ret"] = nRet ;
			sendMsgToPlayer(nSessionID,jsmsgBack,nMsgType) ;
		}
		break ;
	default:
		return false ;
	}
	return true ;
}
コード例 #26
0
 /**
  * \brief Adds a state.
  * \return true if the state requested has already been visited, false otherwise.
  */
 inline pair <StateId, bool> add ( typename KenLMModelT::State& m2nextstate,
                                   StateId m1nextstate, Weight m1stateweight ) {
   static StateId lm = 0;
   getIdx ( m2nextstate );
   ///New history:
   if ( seenlmstates_.find ( history ) == seenlmstates_.end() ) {
     seenlmstates_[history] = ++lm;
   }
   uint64_t compound = m1nextstate * sid + seenlmstates_[history];
   LDEBUG ( "compound id=" << compound );
   if ( stateexistence_.find ( compound ) == stateexistence_.end() ) {
     LDEBUG ( "New State!" );
     statemap_[composed_->NumStates()] =
       pair<StateId, const typename KenLMModelT::State > ( m1nextstate, m2nextstate );
     composed_->AddState();
     if ( m1stateweight != mw_ ( ZPosInfinity() ) ) composed_->SetFinal (
         composed_->NumStates() - 1, m1stateweight );
     stateexistence_[compound] = composed_->NumStates() - 1;
     return pair<StateId, bool> ( composed_->NumStates() - 1, false );
   }
   return pair<StateId, bool> ( stateexistence_[compound], true );
 };
コード例 #27
0
HRESULT CaPerfDataWriter::writeSectionHdr(caperf_section_type_t section, gtUInt64 startOffset, gtUInt64 size)
{
    int ret = S_OK;
    struct caperf_section_hdr hdr;
    memset((void*)&hdr, 0, sizeof(caperf_section_hdr));

    hdr.type = section;
    hdr.offset = startOffset;
    hdr.size = size;
    hdr.misc = 0;

    gtUInt32 idx = getIdx(section);

    if (CAPERF_MAX_SECTIONS > idx)
    {
        // lseek(m_fd, m_offset, SEEK_SET);
        m_offset = lseek(m_fd, 0, SEEK_CUR);

        ssize_t ret = write(m_fd, (const void*)&hdr, sizeof(hdr));

        if (ret == sizeof(hdr))
        {
            m_sectionHdrOffsets[idx] = m_offset;
            m_nbrSections++;

            // set the offset
            m_offset = lseek(m_fd, 0, SEEK_CUR);
        }
        else
        {
            OS_OUTPUT_DEBUG_LOG(L"Error while writing section header", OS_DEBUG_LOG_ERROR);
            ret = E_FAIL;
        }
    }

    return ret;
}
コード例 #28
0
ファイル: Ground.cpp プロジェクト: tcagame/HoneyMiner
GROUND_CHIP_TYPE Ground::getTypeTerrain( int mx, int my ) const {
	if ( mx < 0 || mx >= _width ||
		 my < 0 || my >= _height ) {
			return GROUND_CHIP_TYPE_RIVER;
	}
	GROUND_CHIP_TYPE chip = _array_type[ getIdx( mx, my ) ];
	if ( chip == GROUND_CHIP_TYPE_TREE ) {
		chip = GROUND_CHIP_TYPE_DESERT;
	}
	if ( chip == GROUND_CHIP_TYPE_FLOWER ) {
		chip = GROUND_CHIP_TYPE_PLAIN;
	}
	if ( chip == GROUND_CHIP_TYPE_BEAR ) {
		chip = GROUND_CHIP_TYPE_PLAIN;
	}
	if ( chip == GROUND_CHIP_TYPE_BEE ) {
		chip = GROUND_CHIP_TYPE_PLAIN;
	}
	if ( chip == GROUND_CHIP_TYPE_POWERPLANT ) {
		chip = GROUND_CHIP_TYPE_DESERT;
	}

	return chip;
}
コード例 #29
0
ファイル: CtVolume.cpp プロジェクト: hsaikia/mergetree_old
void CtVolume::findNeighbors(const size_t idx, std::vector<size_t>& neighbors)
{
	neighbors.clear(); //clear keeps memory, but sets size to zero

    const size_t x = idx % L;
    const size_t y = (idx / L) % M;
    const size_t z = (idx / (L * M)) % N; // mod N is not required

    const int dx[3] = {-1, 0, 1};
    const int dy[3] = {-1, 0, 1};
    const int dz[3] = {-1, 0, 1};

    for(size_t i = 0; i < 3; ++i)
    {
        if(x + dx[i] < 0 || x + dx[i] > L - 1) continue;
        for(size_t j = 0; j < 3; ++j)
        {
            if(y + dy[j] < 0 || y + dy[j] > M - 1) continue;
            for(size_t k = 0; k < 3; ++k)
            {
                if(z + dz[k] < 0 || z + dz[k] > N - 1) continue;
                if(dx[i] == 0 && dy[j] == 0 && dz[k] == 0) continue;
                //printf("[x y z] = [%d %d %d]\n", dx[i], dy[j], dz[k]);

                neighbors.push_back( getIdx(x + dx[i], y + dy[j], z + dz[k]) );
            }
        }
    }

	//if(x > 0){
	//	neighbors.push_back(getIdx(x - 1, y, z));
	//}
	//if(x < L - 1){
	//	neighbors.push_back(getIdx(x + 1, y, z));
	//}
	//if(y > 0){
	//	neighbors.push_back(getIdx(x, y - 1, z));
	//}
	//if(y < M - 1){
	//	neighbors.push_back(getIdx(x, y + 1, z));
	//}
	//if(z > 0){
	//	neighbors.push_back(getIdx(x, y, z - 1));
	//}
	//if(z < N - 1){
	//	neighbors.push_back(getIdx(x, y, z + 1));
	//}
	//	if(y > 0 && z > 0){
	//	neighbors.push_back(getIdx(x, y - 1, z - 1));
	//}
	//if(y < M - 1 && z < N - 1){
	//	neighbors.push_back(getIdx(x, y + 1, z + 1));
	//}
	//if(x > 0 && z > 0){
	//	neighbors.push_back(getIdx(x - 1, y, z - 1));
	//}
	//if(x < L - 1 && z < N - 1){
	//	neighbors.push_back(getIdx(x + 1, y, z + 1));
	//}
	//if(y > 0 && x > 0){
	//	neighbors.push_back(getIdx(x - 1, y - 1, z));
	//}
	//if(y < M - 1 && x < L - 1){
	//	neighbors.push_back(getIdx(x + 1, y + 1, z));
	//}
}
コード例 #30
0
void UIBuyBuildingLayer::onCardClick( Ref* sender )
{
    auto card = dynamic_cast<CustomTableViewCell*>(sender);
	//TODO
	//if (_btnCallback && !card->getIsDisable())
	if (_btnCallback)
	{   
		auto buycfg = BuyListConfig::getBuyListFromType( (OpenBuilding::BuyBuildingType)_curtag).at(card->getIdx());
		_btnCallback(this,buycfg);
	}
	this->removeFromParentAndCleanup(true);

}