Example #1
0
void console_widget_t::calc_area(int x, int y)
{
	/* calculate selection area */

	if(mouse_drag_type)
	{
		/* copy rect */
		/* calculate selection start location and selection width and height */

		mouse_sx = i_min(loc_x(mouse_start_x), loc_x(x));
		mouse_wx = i_abs(loc_x(x)-loc_x(mouse_start_x));
		mouse_sy = i_min(loc_y(mouse_start_y), loc_y(y));
		mouse_wy = i_abs(loc_y(y)-loc_y(mouse_start_y));

		/* no point if mouse selection is empty */
		mouse_wx = (mouse_wx == 0) ? 1 : mouse_wx;
		mouse_wy = (mouse_wy == 0) ? 1 : mouse_wy;

		/* clip selection to the size of the console */
		mouse_wx = (mouse_sx+mouse_wx > console->config.x) ?
			console->config.x - mouse_sx : mouse_wx;

		mouse_wy = (mouse_sy+mouse_wy > console->config.y) ?
			console->config.y : mouse_wy;
	}
	else
	{
		/* copy lines */

		/* calculate start and end of selection */
		loc_start = loc_x(mouse_start_x) + loc_y(mouse_start_y) * console->config.x;
		loc_end = loc_x(x) + loc_y(y) * console->config.x;

		/* swap start and end as needed */
		if(loc_start>loc_end)
		{
			int temp = loc_start;
			loc_start = loc_end;
			loc_end = temp;
		}
	}

	return;
}
Example #2
0
int console_widget_t::loc_y(int mouse_y)
{
	/* calculate location of the mouse in screen text coordinates */
	int border_y = (fit_y - h()) / 2;
	int loc_y = (mouse_y-MENU_SIZE_PIXELS+border_y)/letter_y;

	/* clip mouse location to screen only */
	loc_y = i_min(console->config.y, loc_y);
	loc_y = i_max(0, loc_y);
	return loc_y;
}
Example #3
0
int console_widget_t::loc_x(int mouse_x)
{
	/* calculate location of the mouse in screen text coordinates */
	int border_x = (fit_x-w()) / 2;
	int loc_x = (mouse_x+border_x)/letter_x;

	/* clip mouse location to screen only */
	loc_x = i_min(console->config.x, loc_x);
	loc_x = i_max(0, loc_x);
	return loc_x;
}
Example #4
0
void console_widget_t::scroll_back_buffer(int delta)
{
	if(!console)
		return;

	if(mouse_copy)
		mouse_clear();

	/* limit scroll display to scroll buffer */
	scroll_lines += delta;
	scroll_lines = i_max(scroll_lines, console->config.y-console->config.max_y);
	scroll_lines = i_min(scroll_lines, 0);

	damage_console(0, 0, console->config.x, console->config.y);
}
Example #5
0
inline ErrorCode SweptVertexData::get_params(const EntityHandle vhandle,
                                             int &i, int &j, int &k) const
{
  if (TYPE_FROM_HANDLE(vhandle) != MBVERTEX) return MB_FAILURE;

  int hdiff = vhandle - start_handle();

  k = hdiff / (dIJK[0]*dIJK[1]);
  j = (hdiff - (k*dIJK[0]*dIJK[1])) / dIJK[0];
  i = hdiff % dIJK[0];

  k += vertexParams[0].k();
  j += vertexParams[0].j();
  i += vertexParams[0].i();

  return (vhandle >= start_handle() &&
          i >= i_min() && i <= i_max() &&
          j >= j_min() && j <= j_max() &&
          k >= k_min() && k <= k_max()) ? MB_SUCCESS : MB_FAILURE;
}
Example #6
0
inline ErrorCode SweptElementData::get_params(const EntityHandle ehandle,
                                              int &i, int &j, int &k) const
{
  if (TYPE_FROM_HANDLE(ehandle) != TYPE_FROM_HANDLE(start_handle())) return MB_FAILURE;

  int hdiff = ehandle - start_handle();

    // use double ?: test below because on some platforms, both sides of the : are
    // evaluated, and if dIJKm1[1] is zero, that'll generate a divide-by-zero
  k = (dIJKm1[1] > 0 ? hdiff / (dIJKm1[1] > 0 ? dIJKm1[0]*dIJKm1[1] : 1) : 0);
  j = (hdiff - (k*dIJKm1[0]*dIJKm1[1])) / dIJKm1[0];
  i = hdiff % dIJKm1[0];

  k += elementParams[0].k();
  j += elementParams[0].j();
  i += elementParams[0].i();

  return (ehandle >= start_handle() &&
          ehandle < start_handle()+size() &&
          i >= i_min() && i <= i_max() &&
          j >= j_min() && j <= j_max() &&
          k >= k_min() && k <= k_max()) ? MB_SUCCESS : MB_FAILURE;
}
Example #7
0
inline EntityHandle SweptElementData::get_element(const int i, const int j, const int k) const
{
  return start_handle() + (i-i_min()) + (j-j_min())*dIJKm1[0] + (k-k_min())*dIJKm1[0]*dIJKm1[1];
}
Example #8
0
  //! get min params for this vertex
inline void SweptVertexData::min_params(int &i, int &j, int &k) const
{
  i = i_min();
  j = j_min();
  k = k_min();
}
Example #9
0
inline EntityHandle SweptVertexData::get_vertex(const int i, const int j, 
                                                const int k) const
{
  return start_handle() + (i-i_min()) + (j-j_min())*dIJK[0] + 
    (k-k_min())*dIJK[0]*dIJK[1];
}
void    Perlin3DViewerWidget::updatePerlinChunks()
{

    while (!_ChunkGenerator.threadAvailable())
    {

        //
        // first obtain the camera position

        const myGL::Vec3f&    camera_pos = _FreeFly.getPosition();

    #define D_CHUNK (float)(_ChunkGenerator.getChunkSize())
    #define D_CHECK_NEG(l_value)                            \
        ( ( (l_value) < 0 )                                 \
        ? ( (l_value) / D_CHUNK - 1 )    \
        : ( (l_value) / D_CHUNK ) )

        //
        // then obtain the camera chunk position

        myGL::Vec3i i_pos( D_CHECK_NEG( camera_pos.x ),
                           D_CHECK_NEG( camera_pos.y ),
                           D_CHECK_NEG( camera_pos.z ) );

    #undef  D_CHUNK
    #undef  D_CHECK_NEG

        //
        // get the range in chunk (min/max)

        int tmp_dec = Navigator_GlobalValue::pTest->_chunkRange;

        myGL::Vec3i i_min(i_pos.x - tmp_dec, i_pos.y - tmp_dec, i_pos.z - tmp_dec);
        myGL::Vec3i i_max(i_pos.x + tmp_dec, i_pos.y + tmp_dec, i_pos.z + tmp_dec);

        myGL::Vec3i i_inc;

        ///

        myGL::Vec3i i_inc_best_visible;
        float       length_best_visible = std::numeric_limits<float>::max();

        myGL::Vec3i i_inc_best_not_visible;
        float       length_best_not_visible = std::numeric_limits<float>::max();

        for (i_inc.z = i_min.z; i_inc.z <= i_max.z; ++i_inc.z)
            for (i_inc.y = i_min.y; i_inc.y <= i_max.y; ++i_inc.y)
                for (i_inc.x = i_min.x; i_inc.x <= i_max.x; ++i_inc.x)
                {

                    ///
                    /// check if this coord got a chunk

                    bool    no_need_to_go_further = false;

                    for (Perlin3D_Chunk* element : _Perlin3D_Chunks)
                    {
                        const myGL::Vec3i&  tmp_pos = element->getPosition();

                        /// same position
                        if (i_inc == tmp_pos)
                        {
                            no_need_to_go_further = true;
                            break;
                        }
                    }

                    ///
                    /// if yes => loop again

                    if (no_need_to_go_further)
                        continue;

                    /// else => check if visible

                    myGL::Vec3f     tmp_pos1;
                    tmp_pos1.x = (float)i_inc.x * (float)Navigator_GlobalValue::pTest->_chunkSize;
                    tmp_pos1.y = (float)i_inc.y * (float)Navigator_GlobalValue::pTest->_chunkSize;
                    tmp_pos1.z = (float)i_inc.z * (float)Navigator_GlobalValue::pTest->_chunkSize;

                    bool    is_visible = _Frustum.cubeInFrustum( tmp_pos1, (float)Navigator_GlobalValue::pTest->_chunkSize );

                    ///   check his length
                    ///   reccord these data for the choice

                    myGL::Vec3f     tmp_pos2;
                    tmp_pos2.x = (float)(i_inc.x - i_pos.x) * (float)Navigator_GlobalValue::pTest->_chunkSize;
                    tmp_pos2.y = (float)(i_inc.y - i_pos.y) * (float)Navigator_GlobalValue::pTest->_chunkSize;
                    tmp_pos2.z = (float)(i_inc.z - i_pos.z) * (float)Navigator_GlobalValue::pTest->_chunkSize;

                    float   tmp_lenght = sqrtf( tmp_pos2.x * tmp_pos2.x +
                                                tmp_pos2.y * tmp_pos2.y +
                                                tmp_pos2.z * tmp_pos2.z );

                    if (is_visible)
                    {
                        if (tmp_lenght < length_best_visible)
                        {
                            i_inc_best_visible = i_inc;
                            length_best_visible = tmp_lenght;
                        }
                    }
                    else
                    {
                        if (tmp_lenght < length_best_not_visible)
                        {
                            i_inc_best_not_visible = i_inc;
                            length_best_not_visible = tmp_lenght;
                        }
                    }

                }


        if ( length_best_visible == std::numeric_limits<float>::max() &&
             length_best_not_visible == std::numeric_limits<float>::max() )
            // break;
            return;


        Perlin3D_Chunk* tmp_Chunk = NULL;


        t_Chunks::iterator  itC = _Perlin3D_Chunks.begin();
        // for (; itC != _Perlin3D_Chunks.end(); ++itC)
        for (; itC != _Perlin3D_Chunks.end(); )
        {
            const myGL::Vec3i&  tmp_pos = (*itC)->getPosition();

            if ( !(*itC)->isDisabled() && (
                 tmp_pos.x < i_min.x || tmp_pos.x > i_max.x ||
                 tmp_pos.y < i_min.y || tmp_pos.y > i_max.y ||
                 tmp_pos.z < i_min.z || tmp_pos.z > i_max.z ) )
            {
                delete *itC, *itC = NULL;
                itC = _Perlin3D_Chunks.erase(itC);
                // break;
            }
            else
            {
                ++itC;
            }
        }

        // if ( itC == _Perlin3D_Chunks.end() )
        {
            tmp_Chunk = new Perlin3D_Chunk();
            _Perlin3D_Chunks.push_back( tmp_Chunk );
        }
        // else
        // {
        //     tmp_Chunk = *itC;
        //     tmp_Chunk->releaseBuffers();
        // }


        if ( length_best_visible != std::numeric_limits<float>::max() )
            _ChunkGenerator.generate( i_inc_best_visible, tmp_Chunk );
        else
            _ChunkGenerator.generate( i_inc_best_not_visible, tmp_Chunk );


        // if ( length_best_visible != std::numeric_limits<float>::max() )
        // {
        //     PerlinNoise _PerlinNoise;
        //     {
        //         int     octaves = 1;
        //         float   freq = 1.0f;
        //         float   amp = 1.0f;
        //         int     seed = 0;

        //         _PerlinNoise.Set( octaves, freq, amp, seed );
        //     }

        //     MarchingCube    _marchingCube;
        //     _marchingCube._PerlinNoise = &_PerlinNoise;
        //     _marchingCube.setChunkSize(20);
        //     _marchingCube.prepare(i_inc_best_visible, tmp_Chunk);
        //     _marchingCube.execute();
        // }
        // else
        // {
        //     // // _marchingCube._PerlinNoise = &p;
        //     // _marchingCube.setChunkSize(chunk_size);
        //     // _marchingCube.prepare(i_inc_best_not_visible, pPerlin3D_Chunk);
        //     // _marchingCube.execute();
        // }

        
    }
}
Example #11
0
void ahc_clustering(DyArray *ahct, int bf, int rho, const fDataSet *ds){
	ASSERTINFO(ahct == NULL || bf <= 0 || rho <= 0 || ds == NULL, "IPP");

	int		n 	= ds->n;
	int		d 	= ds->d;
	Cluster	_clu, clu, *pclu = NULL, *p0clu = NULL;
	int		i;
	float	qerror;
	int		iclu, bfi, ni, ichild, ori_id;			// the pointer, branch factor and volume of the i-th cluster
	int 	*nassign = ivec_new_set(bf, 0);
	int 	*assign = NULL;
	float	*cent = fvec_new(d*bf);
	float	*mem_points = NULL;
	DyArray	*member = (DyArray*)malloc(sizeof(DyArray)*bf);

	/* initialize the first cluster (root) to add it to the ahc tree */
	Cluster_init(&clu, n);
	for(i = 0; i < n; i++){
		clu.idx[i] = i;
	}
	clu.type = ClusterType_Root;
	DyArray_add(ahct, (void*)&clu, 1);

	/* begin the loop of adaptive hierarchical clustering */
	iclu = 0;
	while(iclu < ahct->count){
		/* deal with the i-th cluster */
		// figure out the adaptive branch factor of the i-th cluster
		pclu = (Cluster*)DyArray_get(ahct, iclu, 1);
		ni = pclu->npts;
		bfi = i_min(bf, (int)round(ni / (float)rho));

		// deal with the cluster according to its size
		if(bfi < 2){
			/*
			 *	this is a leaf cluster
			 *	- mark it, release the children
			 *	* not necessary to store real data points
			 */
			pclu->type = ClusterType_Leaf;
		}else{
			printf("----------------- cluster %d, bfi-%d:\n", iclu, bfi);

			/*
			 * this is an inner cluster
			 * - divide it
			 */
			memcpy(&_clu, pclu, sizeof(Cluster));

			// extract data points from the original dataset according to the idx
			mem_points = fvec_new(ni * d);
			for(i = 0; i < ni; i++){
				memcpy(mem_points+i*d, ds->data+_clu.idx[i]*d, d);
			}

			// divide this cluster
			assign = ivec_new(ni);

			if(iclu == 30){
				int _a = 1;
				_a++;

				ivec_print(_clu.idx, _clu.npts);
			}

			qerror = kmeans(	d, ni, bfi, CLUSTERING_NITER, mem_points,
								CLUSTERING_NTHREAD | KMEANS_QUIET | KMEANS_INIT_BERKELEY, CLUSTERING_SEED, CLUSTERING_NREDO,
								cent, NULL, assign, nassign);

			// prepare space for members' ids
			for(i = 0; i < bfi; i++){
				DyArray_init(&member[i], sizeof(int), nassign[i]);
			}
			// extract member points' ids for each children cluster
			for(i = 0; i < ni; i++){
				ori_id = _clu.idx[i];
				DyArray_add(&member[assign[i]], (void*)&ori_id, 1);
			}

			// fulfill the type, centroids and the children of this cluster, add them to the ahct
			_clu.type = ClusterType_Inner;
			_clu.cents = fvec_new(d * bfi);
			memcpy(_clu.cents, cent, sizeof(float)*d*bfi);

			DyArray_init(&_clu.children, sizeof(int), bfi);
			for(i = 0; i < bfi; i++){
				Cluster_init(&clu, nassign[i]);
				memcpy(clu.idx, (int*)member[i].elem, sizeof(int)*nassign[i]);

				DyArray_add(&_clu.children, (void*)&ahct->count, 1);	/* the i-th child's position */
				DyArray_add(ahct, (void*)&clu, 1);						/* add the i-th child to the ahct */
			}

			/* as per the elems of ahct may change when expanding the space
			 * we decide to get the brand new address of the element
			 */
			pclu = (Cluster*)DyArray_get(ahct, iclu, 1);
			memcpy(pclu, &_clu, sizeof(Cluster));


			/* report */
			ivec_print(nassign, bfi);
			ivec_print((int*)_clu.children.elem, _clu.children.count);

			/* unset or release */
			FREE(mem_points);
			FREE(assign);
			for(i = 0; i < bfi; i++){
				DyArray_unset(&member[i]);
			}
		}

		// move to next cluster
		iclu++;
	}

	FREE(nassign);
	FREE(cent);
	FREE(member);
	pclu = NULL;
}