Skip to content

Implement OASIS file writer#674

Open
c1ydehhx wants to merge 4 commits intosolvcon:masterfrom
c1ydehhx:manhattan-1-delta-writer
Open

Implement OASIS file writer#674
c1ydehhx wants to merge 4 commits intosolvcon:masterfrom
c1ydehhx:manhattan-1-delta-writer

Conversation

@c1ydehhx
Copy link
Collaborator

@c1ydehhx c1ydehhx commented Feb 4, 2026

In this PR, I added OASIS device. This device support writer only currently. This writer implement manhattan delta format by OASIS spec.

For example, if we expected +340 for N/S direction, it will be encoded with 0xD0 0x0A, and -340 will be 0xD2 0x0A.

I added some test to make sure it work properly, and I add some edge case to make sure it will not buggy when met edge case.

Copy link
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points to address:

  • Write OASIS I/O code in C++. Name it modmesh::OasisDevice. Wrap it to Python for testing.
  • Manually verify the written file by loading it using a third-party viewer and paste the screenshot.

# POSSIBILITY OF SUCH DAMAGE.


class ManhattanDeltaCodec:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write I/O code in C++. Python is too slow to be taken seriously for I/O.

Name it modmesh::OasisDevice for now.

from modmesh.plot import plane_layer


class ManhattanDeltaCodecTC(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests for the OASIS I/O should be in Python.

@yungyuc yungyuc added the geometry Geometry entities and manipulation label Feb 4, 2026
@yungyuc yungyuc changed the title Implement Manhattan Delta Codec writer Implement OASIS file writer Feb 4, 2026
@c1ydehhx c1ydehhx force-pushed the manhattan-1-delta-writer branch from 8a2d55c to eb97718 Compare February 5, 2026 15:51
@c1ydehhx
Copy link
Collaborator Author

c1ydehhx commented Feb 5, 2026

Hi @yungyuc,
So far away, I already migrate Manhatten 1-delta writer (Named it OasisWriter) from Python to C++, and use pybind11 to wrap it as a module.

Write OASIS I/O code in C++. Name it modmesh::OasisDevice. Wrap it to Python for testing.

Done.

Manually verify the written file by loading it using a third-party viewer and paste the screenshot.

I'm concern that it will have too much diff in this PR if we want to output OASIS file. Althought we have geometry record now, we don't have some necessary OASIS header like magic bytes, START and END.

I would like to confirm that this PR should support OASIS file output or we can just test Manhatten 1-delta work properly with unit tests?

@yungyuc
Copy link
Member

yungyuc commented Feb 6, 2026

Linter did not pass. Please fix code format and then request for review again.

Copy link
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some very basic points to address:

  • Do not make an intrusive alias in global namespace and for STL things like std::vector<uint8)_t>.
  • Rule of 5 for OasisDevice.
  • Name as OasisDevice::write, not writer, which is not a verb.

#include <cstdint>
#include <vector>

using bytes = std::vector<uint8_t>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not make an intrusive alias like this. It is horrible to maintain.

There is nothing wrong with using std::vector<uint8)_t>? Just spell out the type.

It is horrible to add an alias in the global name space. Unacceptable almost always.

static void append_1_delta(bytes & segment, int value);

public:
OasisDevice() = default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule of 5.


public:
OasisDevice() = default;
static bytes writer(std::vector<int32_t> & values);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name it write, not writer, which is not a verb.

@yungyuc
Copy link
Member

yungyuc commented Feb 6, 2026

@tigercosmos @KHLee529 please help review

@c1ydehhx c1ydehhx force-pushed the manhattan-1-delta-writer branch from 71b53ff to d3e62a3 Compare February 6, 2026 15:07
namespace python
{

using namespace modmesh::oasis; // NOLINT(google-build-using-namespace)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend remove this. Namespace is important for reading the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. modmesh::oasis namespace is not necessary and should be removed.

And, never using namespace unless it is in a very limited scope and can resolve extreme pain.


void OasisDevice::append_1_delta(std::vector<uint8_t> & segment, int value)
{
int dir_bit = value < 0 ? 1 : 0;
Copy link
Collaborator

@tigercosmos tigercosmos Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add const for all the places if applicable.

namespace oasis
{

class OasisDevice
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add document comments for classes and functions.

}
}

std::vector<uint8_t> OasisDevice::write(std::vector<int32_t> & values)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::vector<int32_t> & values

namespace oasis
{

void OasisDevice::append_1_delta(std::vector<uint8_t> & segment, int value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a local function in cpp only.

while (payload >= 1)
{
int first_bit = payload >= 128 ? 1 : 0;
segment.push_back((first_bit << 7) | (payload % 128));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments to explain the algorithm. Including source doucment is even better.

# POSSIBILITY OF SUCH DAMAGE.


class ManhattanDeltaCodec:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it.

device = modmesh.OasisDevice()
seg = device.writer([+340, +200, -340, -40, +300, -120, -300])

self.assertEqual(seg, [0xD0, 0x0A, 0xA0, 0x06, 0xD2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be nice if you can explain what you try to test in the comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use code comments to explain.

Copy link
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points to address:

  • Do not use namespace modmesh::oasis.
  • Add very concise code comments for the key points in unit tests.

namespace python
{

using namespace modmesh::oasis; // NOLINT(google-build-using-namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. modmesh::oasis namespace is not necessary and should be removed.

And, never using namespace unless it is in a very limited scope and can resolve extreme pain.

namespace modmesh
{

namespace oasis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use namespace modmesh::oasis.

device = modmesh.OasisDevice()
seg = device.writer([+340, +200, -340, -40, +300, -120, -300])

self.assertEqual(seg, [0xD0, 0x0A, 0xA0, 0x06, 0xD2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use code comments to explain.

@c1ydehhx c1ydehhx force-pushed the manhattan-1-delta-writer branch from 012b646 to 5607f69 Compare February 7, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

geometry Geometry entities and manipulation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants