void IsotropicParticleMesher::_computeSliceScalarField(int startidx, int endidx, 
	                                                   FragmentedVector<MarkerParticle> &markerParticles,
	                                                   FluidMaterialGrid &materialGrid,
	                                                   ImplicitSurfaceScalarField &field) {
	
	FragmentedVector<vmath::vec3> sliceParticles;
	_getSliceParticles(startidx, endidx, markerParticles, sliceParticles);

	int width, height, depth;
	field.getGridDimensions(&width, &height, &depth);

	FluidMaterialGrid sliceMaterialGrid(width - 1, height - 1, depth - 1);
	_getSliceMaterialGrid(startidx, endidx, materialGrid, sliceMaterialGrid);

	field.setMaterialGrid(sliceMaterialGrid);

	vmath::vec3 fieldOffset = _getSliceGridPositionOffset(startidx, endidx);
	field.setOffset(fieldOffset);
	field.setPointRadius(_particleRadius);

	for (unsigned int i = 0; i < sliceParticles.size(); i++) {
        field.addPoint(sliceParticles[i]);
    }

    _updateScalarFieldSeam(startidx, endidx, field);
}
void IsotropicParticleMesher::_applyScalarFieldSliceSeamData(ImplicitSurfaceScalarField &field) {
	int width, height, depth;
	field.getGridDimensions(&width, &height, &depth);

	for (int k = 0; k < depth; k++) {
		for (int j = 0; j < height; j++) {
			for (int i = 0; i <= 2; i++) {
				field.setScalarFieldValue(i, j, k, _scalarFieldSeamData(i, j, k));
			}
		}
	}
}
void IsotropicParticleMesher::_saveScalarFieldSliceSeamData(ImplicitSurfaceScalarField &field) {
	int width, height, depth;
	field.getGridDimensions(&width, &height, &depth);

	_scalarFieldSeamData = Array3d<float>(3, height, depth);
	for (int k = 0; k < depth; k++) {
		for (int j = 0; j < height; j++) {
			for (int i = 0; i <= 2; i++) {
				_scalarFieldSeamData.set(i, j, k, field.getRawScalarFieldValue(i + width - 3, j, k));
			}
		}
	}
}
void IsotropicParticleMesher::_addPointsToScalarField(FragmentedVector<MarkerParticle> &points,
	                                                  ImplicitSurfaceScalarField &field) {
	if (_isScalarFieldAcceleratorSet) {
		_addPointsToScalarFieldAccelerator(points, field);
	} else {
		for (unsigned int i = 0; i < points.size(); i++) {
	        field.addPoint(points[i].position);
	    }
	}
}