コード例 #1
0
ファイル: GteImageUtility3.cpp プロジェクト: yimogod/gt_learn
void ImageUtility3::Dilate(int numNeighbors, std::array<int, 3> const* delta,
    Image3<int> const& inImage, Image3<int>& outImage)
{
    int const bound0M1 = inImage.GetDimension(0) - 1;
    int const bound1M1 = inImage.GetDimension(1) - 1;
    int const bound2M1 = inImage.GetDimension(2) - 1;
    for (int i2 = 1; i2 < bound2M1; ++i2)
    {
        for (int i1 = 1; i1 < bound1M1; ++i1)
        {
            for (int i0 = 1; i0 < bound0M1; ++i0)
            {
                if (inImage(i0, i1, i2) == 0)
                {
                    for (int n = 0; n < numNeighbors; ++n)
                    {
                        int d0 = delta[n][0];
                        int d1 = delta[n][1];
                        int d2 = delta[n][2];
                        if (inImage(i0 + d0, i1 + d1, i2 + d2) == 1)
                        {
                            outImage(i0, i1, i2) = 1;
                            break;
                        }
                    }
                }
                else
                {
                    outImage(i0, i1, i2) = 1;
                }
            }
        }
    }
}
コード例 #2
0
//----------------------------------------------------------------------------
void ImageUtility3::GetComponents18(Image3<int>& image,
    std::vector<std::vector<int> >& components)
{
    // Incremental 1D offsets for 18-connected neighbors.  Store +1 and -1
    // first, the xy-offsets second, to be cache friendly during the
    // depth-first search.
    int const dim0 = image.GetDimension(0);
    int const dim01 = dim0*image.GetDimension(1);
    int const delta[18] =
    {
        +1,
        -1,
        -1 - dim0,
        0 - dim0,
        +1 - dim0,
        -1 + dim0,
        0 + dim0,
        +1 + dim0,
        0 + dim01,
        +1 + dim01,
        -1 + dim01,
        0 - dim0 + dim01,
        0 + dim0 + dim01,
        0 - dim01,
        +1 - dim01,
        -1 - dim01,
        0 - dim0 - dim01,
        0 + dim0 - dim01
    };

    GetComponents(18, delta, image, components);
}
コード例 #3
0
ファイル: Material.cpp プロジェクト: CPPEngine/CPPEngine
//-------------------------------------------------------------------------------
int CMaterialManager::SetDefaultTexture(TextureID* p_ppiOut)
{
		Image3 img;
		img.create(
			FORMAT_RGBA8,//???
			256,
		256,1,1);
		*p_ppiOut=IRenderer::GetRendererInstance()->addTexture(
			&img,
			false,
			IRenderer::GetRendererInstance()->Getlinear()
			,STATIC);
	return 1;
}
コード例 #4
0
ファイル: GteImageUtility3.cpp プロジェクト: yimogod/gt_learn
void ImageUtility3::Dilate26(Image3<int> const& inImage,
    Image3<int>& outImage)
{
    std::array<std::array<int, 3>, 26> neighbors;
    inImage.GetNeighborhood(neighbors);
    Dilate(26, &neighbors[0], inImage, outImage);
}
コード例 #5
0
ファイル: GteImageUtility3.cpp プロジェクト: yimogod/gt_learn
void ImageUtility3::GetComponents26(Image3<int>& image,
    std::vector<std::vector<size_t>>& components)
{
    std::array<int, 26> neighbors;
    image.GetNeighborhood(neighbors);
    GetComponents(26, &neighbors[0], image, components);
}
コード例 #6
0
//----------------------------------------------------------------------------
void ImageUtility3::GetComponents6(Image3<int>& image,
    std::vector<std::vector<int> >& components)
{
    // Incremental 1D offsets for 6-connected neighbors.  Store +1 and -1
    // first to be cache friendly during the depth-first search.
    int const dim0 = image.GetDimension(0);
    int const dim01 = dim0*image.GetDimension(1);
    int const delta[6] =
    {
        +1,
        -1,
        -dim0,
        +dim0,
        +dim01,
        -dim01
    };

    GetComponents(6, delta, image, components);
}
コード例 #7
0
//---------------------------------------------------------------------------
void SetInitial3 (Image3<float>& initial)
{
    const int n0 = initial.GetDimension(0);
    const int n1 = initial.GetDimension(1);
    const int n2 = initial.GetDimension(2);
    for (int i2 = 0; i2 < n2; ++i2)
    {
        float x2 = -1.0f + 2.0f*i2/(float)(n2-1);
        float value2 = 1.0f - x2*x2;
        for (int i1 = 0; i1 < n1; ++i1)
        {
            float x1 = -1.0f + 2.0f*i1/(float)(n1-1);
            float value1 = 1.0f - x1*x1;
            float value12 = value1*value2;
            for (int i0 = 0; i0 < n0; ++i0)
            {
                float x0 = -1.0f + 2.0f*i0/(float)(n0-1);
                float value0 = 1.0f - x0*x0;
                initial(i0, i1, i2) = value0*value12;
            }
        }
    }
}
コード例 #8
0
ファイル: Material.cpp プロジェクト: CPPEngine/CPPEngine
//-------------------------------------------------------------------------------
int CMaterialManager::LoadTexture(TextureID* p_ppiOut,aiString* szPath)
{	
	//???ai_assert(-1 != *p_ppiOut);
	ai_assert(0 != szPath);

	*p_ppiOut = -1;
#if 1

	LOG_PRINT("szPath=%s\n", szPath);
	// first get a valid path to the texture
	if( 5 == FindValidPath(szPath))
	{
		// embedded file. Find its index
		unsigned int iIndex = atoi(szPath->data+1);
		if (iIndex < mr->GetAsset()->pcScene->mNumTextures)
		{
/*			if (0 == mr->GetAsset()->pcScene->mTextures[iIndex]->mHeight)
			{
				// it is an embedded file ... don't need the file format hint,
				// simply let D3DXFROMWINE load the file
				if (FAILED(D3DXFROMWINECreateTextureFromFileInMemoryEx(mr->m_piDevice,
					mr->GetAsset()->pcScene->mTextures[iIndex]->pcData,
					mr->GetAsset()->pcScene->mTextures[iIndex]->mWidth,
					D3DXFROMWINE_DEFAULT,
					D3DXFROMWINE_DEFAULT,
					0,
					D3DUSAGE_AUTOGENMIPMAP,
					D3DFMT_UNKNOWN,
					D3DPOOL_MANAGED,
					D3DXFROMWINE_DEFAULT,
					D3DXFROMWINE_DEFAULT,
					0,
					0,
					0,
					p_ppiOut)))
				{
					std::string sz = "[ERROR] Unable to load embedded texture (#1): ";
					sz.append(szPath->data);
					//CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));

					this->SetDefaultTexture(p_ppiOut);
					return 1;
				}
			}
			else*/
			{
				// fill a new texture ...
		Image3 img;

		BYTE* dst=img.create(
			FORMAT_RGBA8,//???
			mr->GetAsset()->pcScene->mTextures[iIndex]->mWidth,
					mr->GetAsset()->pcScene->mTextures[iIndex]->mHeight,1,1);
		//BYTE* dst=img.getPixels();


				// now copy the data to it ... (assume non pow2 to be supported)

//D3DLOCKED_RECT sLock;

	//	sLock.pBits=IRenderer::GetRendererInstance()->LockTexture(*p_ppiOut, 0, sLock.Pitch);

				const aiTexel* pcData = mr->GetAsset()->pcScene->mTextures[iIndex]->pcData;

				for (unsigned int y = 0; y < mr->GetAsset()->pcScene->mTextures[iIndex]->mHeight;++y)
				{
					stx_memcpy(dst,pcData,mr->GetAsset()->pcScene->mTextures[iIndex]->
						mWidth *sizeof(aiTexel));
					dst = (BYTE *)dst + 4*mr->GetAsset()->pcScene->mTextures[iIndex]->mWidth;
					pcData += mr->GetAsset()->pcScene->mTextures[iIndex]->mWidth;
				}
  //  IRenderer::GetRendererInstance()->UnlockTexture(*p_ppiOut, 0);
//				(*p_ppiOut)->GenerateMipSubLevels();

		*p_ppiOut=IRenderer::GetRendererInstance()->addTexture(
			&img,
			false,
			IRenderer::GetRendererInstance()->Getlinear()
			,STATIC);

			}
			return 1;
		}
		else
		{
			std::string sz = "[ERROR] Invalid index for embedded texture: ";
			sz.append(szPath->data);
			//CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));

			SetDefaultTexture(p_ppiOut);
			return 1;
		}
	}

    	////LOG_PRINT("mr->m_piDevice=%x\n", mr->m_piDevice);
	//DBG_HALT;
	// then call D3DXFROMWINE to load the texture
	//D3DFMT_A8R8G8B8,
#endif
	std::string f1=szPath->data;
	LOG_FNLN;
	LOG_PRINT("Assimp Mesh Texture:%s\n", f1.c_str());
#if 1
		*p_ppiOut=//IRenderer::GetRendererInstance()->
			IRenderer::GetRendererInstance()->addImageLibTexture(
			f1.c_str(),
			false,
			IRenderer::GetRendererInstance()->Getlinear()
			,STATIC
			);
#else
	Image3 img;
	if (img.loadImageLibImage(szPath->data, false))
	{
		img.createMipMaps();
		*p_ppiOut=IRenderer::GetRendererInstance()->addTexture(&img,false, IRenderer::GetRendererInstance()->Getlinear(),STATIC,0.0f,false);
	}
#endif
	return 1;
}
コード例 #9
0
ファイル: GteImageUtility3.cpp プロジェクト: yimogod/gt_learn
void ImageUtility3::ComputeCDConvex(Image3<int>& image)
{
    int const dim0 = image.GetDimension(0);
    int const dim1 = image.GetDimension(1);
    int const dim2 = image.GetDimension(2);

    Image3<int> temp = image;
    int i0, i1, i2;
    for (i1 = 0; i1 < dim1; ++i1)
    {
        for (i0 = 0; i0 < dim0; ++i0)
        {
            int i2min;
            for (i2min = 0; i2min < dim2; ++i2min)
            {
                if ((temp(i0, i1, i2min) & 1) == 0)
                {
                    temp(i0, i1, i2min) |= 2;
                }
                else
                {
                    break;
                }
            }
            if (i2min < dim2)
            {
                int i2max;
                for (i2max = dim2 - 1; i2max >= i2min; --i2max)
                {
                    if ((temp(i0, i1, i2max) & 1) == 0)
                    {
                        temp(i0, i1, i2max) |= 2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    for (i2 = 0; i2 < dim2; ++i2)
    {
        for (i0 = 0; i0 < dim0; ++i0)
        {
            int i1min;
            for (i1min = 0; i1min < dim1; ++i1min)
            {
                if ((temp(i0, i1min, i2) & 1) == 0)
                {
                    temp(i0, i1min, i2) |= 2;
                }
                else
                {
                    break;
                }
            }
            if (i1min < dim1)
            {
                int i1max;
                for (i1max = dim1 - 1; i1max >= i1min; --i1max)
                {
                    if ((temp(i0, i1max, i2) & 1) == 0)
                    {
                        temp(i0, i1max, i2) |= 2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    for (i2 = 0; i2 < dim2; ++i2)
    {
        for (i1 = 0; i1 < dim1; ++i1)
        {
            int i0min;
            for (i0min = 0; i0min < dim0; ++i0min)
            {
                if ((temp(i0min, i1, i2) & 1) == 0)
                {
                    temp(i0min, i1, i2) |= 2;
                }
                else
                {
                    break;
                }
            }
            if (i0min < dim0)
            {
                int i0max;
                for (i0max = dim0 - 1; i0max >= i0min; --i0max)
                {
                    if ((temp(i0max, i1, i2) & 1) == 0)
                    {
                        temp(i0max, i1, i2) |= 2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }

    for (size_t i = 0; i < image.GetNumPixels(); ++i)
    {
        image[i] = (temp[i] & 2 ? 0 : 1);
    }
}
コード例 #10
0
ファイル: GteImageUtility3.cpp プロジェクト: yimogod/gt_learn
void ImageUtility3::GetComponents(int numNeighbors, int const* delta,
    Image3<int>& image, std::vector<std::vector<size_t>>& components)
{
    size_t const numVoxels = image.GetNumPixels();
    int* numElements = new int[numVoxels];
    size_t* vstack = new size_t[numVoxels];
    size_t i, numComponents = 0;
    int label = 2;
    for (i = 0; i < numVoxels; ++i)
    {
        if (image[i] == 1)
        {
            int top = -1;
            vstack[++top] = i;

            int& count = numElements[numComponents + 1];
            count = 0;
            while (top >= 0)
            {
                size_t v = vstack[top];
                image[v] = -1;
                int j;
                for (j = 0; j < numNeighbors; ++j)
                {
                    size_t adj = v + delta[j];
                    if (image[adj] == 1)
                    {
                        vstack[++top] = adj;
                        break;
                    }
                }
                if (j == numNeighbors)
                {
                    image[v] = label;
                    ++count;
                    --top;
                }
            }

            ++numComponents;
            ++label;
        }
    }
    delete[] vstack;

    if (numComponents > 0)
    {
        components.resize(numComponents + 1);
        for (i = 1; i <= numComponents; ++i)
        {
            components[i].resize(numElements[i]);
            numElements[i] = 0;
        }

        for (i = 0; i < numVoxels; ++i)
        {
            int value = image[i];
            if (value != 0)
            {
                // Labels started at 2 to support the depth-first search,
                // so they need to be decremented for the correct labels.
                image[i] = --value;
                components[value][numElements[value]] = i;
                ++numElements[value];
            }
        }
    }
    delete[] numElements;
}