Microsoft MVP성태의 닷넷 이야기
.NET Framework: 839. C# - PLplot 색상 제어 [링크 복사], [링크+제목 복사],
조회: 10028
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)

C# - PLplot 색상 제어

저도 확실히는 모르지만, 일단 그냥 코드 상으로 본 것만 기록을 남기려고 합니다.

우선, PLplot은 palette 개념이 있는 듯한데 기본적으로 16개 공간만 있고 다음의 코드를 통해 확인할 수 있습니다.

using (var pl = new PLStream())
{
    for (int i = 0; i < 20; i ++)
    {
        pl.gcol0(i, out int r, out int g, out int b);
        Console.WriteLine($"{i} == {r}, {g}, {b}");
    }
}

/*
0 == 0, 0, 0
1 == 255, 0, 0
2 == 255, 255, 0
3 == 0, 255, 0
4 == 127, 255, 212
5 == 255, 192, 203
6 == 245, 222, 179
7 == 190, 190, 190
8 == 165, 42, 42
9 == 0, 0, 255
10 == 138, 43, 226
11 == 0, 255, 255
12 == 64, 224, 208
13 == 255, 0, 255
14 == 250, 128, 114
15 == 255, 255, 255
16 == 0, 0, 0
... 17번 부터는 다음과 같은 식으로 오류 발생
*** PLPLOT ERROR, ABORTING OPERATION ***
plgcol0: Invalid color index: 17, aborting operation
17 == -1, -1, -1
*/

위의 컬러 값에 대한 상수 값은 다음과 같이 미리 정의되어 있습니다.

namespace PLplot
{
    public static class Color
    {
        public const int Black = 0;
        public const int Red = 1;
        public const int Yellow = 2;
        public const int Green = 3;
        public const int Aquamarine = 4;
        public const int Pink = 5;
        public const int Wheat = 6;
        public const int Grey = 7;
        public const int Brown = 8;
        public const int Blue = 9;
        public const int BlueViolet = 10;
        public const int Cyan = 11;
        public const int Turquoise = 12;
        public const int Magenta = 13;
        public const int Salmon = 14;
        public const int White = 15;
    }
}

당연히 palette 값은 수정될 수 있고, 이것을 미리 정의한 테마 파일들이 바이너리가 놓인 폴더 하위 "plplot"에 담겨 있습니다. (nuget인 경우, "%USERPROFILE%\.nuget\packages\plplot\5.13.7\runtimes\win-x64\native\plplot" 폴더)

cmap0_alternate.pal
cmap0_black_on_white.pal
cmap0_default.pal
cmap0_white_bg.pal
cmap1_blue_red.pal
cmap1_blue_yellow.pal
cmap1_default.pal
cmap1_gray.pal
cmap1_highfreq.pal
cmap1_lowfreq.pal
cmap1_radar.pal

각각의 pal 파일은 텍스트 파일로 16개의 palette 색상 값을 재정의한 RGB 값을 포함합니다. 예를 들어 "cmap0_alternate.pal" 파일은 다음과 같습니다.

16
#ffffff
#000000
#0000ff
#ff0000
#a52a2a
#fa8072
#ffc0cb
#7fffd4
#f5deb3
#40e0d0
#bebebe
#00ffff
#00ff00
#ffff00
#ff00ff
#8a2be2

그러니까 가령 pl.col0 값으로 Black 인덱스를 설정한 경우,

pl.col0(PLplot.Color.Black); // 검정색 지정

기본 palette 설정에서는 검은색으로 나오겠지만, cmap0_alternate.pal 테마를 설정한 경우에는 동일한 코드가,

pl.spal0("cmap0_alternate.pal");
pl.col0(PLplot.Color.Black);

"#ffffff" 하얀색으로 바뀌게 되는 것입니다. 참고로, 기본 palette도 "cmap0_default.pal"이름으로 저장되어 있으며 다음과 같이 빈 문자열을 주면,

pl.spal0(""); // cmap0_default.pal 선택

기본 palette이 선택됩니다. (null을 주면 System.AccessViolationException 예외가 발생합니다)




palette은 코드 중간에 바뀌는 것이 허용됩니다. 예를 들어, 기본 상태에서는 다음과 같이 검은 바탕에 빨간색 축이지만,

plplot_color_1.png

pl.init() 호출 전에 palette을 바꿔주면,

pl.spal0("cmap0_alternate.pal");
pl.init();

(테마에 재정의되었으므로) 하얀색 바탕에 검은색 축이 그려지고, 이후 다시 spal0 호출로 바꿔주면 그에 따른 색상 인덱스를 지정할 수 있습니다.

pl.spal0("cmap0_alternate.pal");
pl.init();

pl.env(xMin, xMax, yMin, yMax, AxesScale.Independent, AxisBox.BoxTicksLabelsAxes);
pl.lab("X", "Y", "Click");

char code = Symbol.Bullet;
pl.spal0(""); // 기본 palette으로 복구했으므로,
pl.col0(PLplot.Color.Blue); // Blue 인덱스의 의미에 따라 파란색 점으로 출력
pl.poin(xData, yData, code);

plplot_color_2.png

개인적인 생각으로는, PLplot.Color 상수를 사용하는 경우에는 palette을 기본 설정한 상태로 써야 혼란이 없을 것이고 만약 palette을 바꾼 상태에서 쓰고 싶다면 바뀐 테마에 맞게 상수를 새롭게 정의해서 쓰는 것이 좋을 듯합니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 5/28/2019]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12419정성태11/19/20209220VC++: 139. Visual C++ - .NET Core의 nethost.lib와 정적 링크파일 다운로드1
12418정성태11/19/202011255오류 유형: 683. Visual C++ - error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug'파일 다운로드1
12417정성태11/19/20208657오류 유형: 682. Visual C++ - warning LNK4099: PDB '...pdb' was not found with '...lib(pch.obj)' or at '...pdb'; linking object as if no debug info
12416정성태11/19/20209935오류 유형: 681. Visual C++ - error LNK2001: unresolved external symbol _CrtDbgReport
12415정성태11/18/202010021.NET Framework: 971. UnmanagedCallersOnly 특성과 DNNE 사용파일 다운로드1
12414정성태11/18/202011078VC++: 138. x64 빌드에서 extern "C"가 아닌 경우 ___cdecl name mangling 적용 [4]파일 다운로드1
12413정성태11/17/202010755.NET Framework: 970. .NET 5 / .NET Core - UnmanagedCallersOnly 특성을 사용한 함수 내보내기파일 다운로드1
12412정성태11/16/202013003.NET Framework: 969. .NET Framework 및 .NET 5 - UnmanagedCallersOnly 특성 사용파일 다운로드1
12411정성태11/12/20209989오류 유형: 680. C# 9.0 - Error CS8889 The target runtime doesn't support extensible or runtime-environment default calling conventions.
12410정성태11/12/20209914디버깅 기술: 174. windbg - System.TypeLoadException 예외 분석 사례
12409정성태11/12/202011290.NET Framework: 968. C# 9.0의 Function pointer를 이용한 함수 주소 구하는 방법파일 다운로드1
12408정성태11/9/202022790도서: 시작하세요! C# 9.0 프로그래밍 [8]
12407정성태11/9/202011573.NET Framework: 967. "clr!JIT_DbgIsJustMyCode" 호출이 뭘까요?
12406정성태11/8/202013163.NET Framework: 966. C# 9.0 - (15) 최상위 문(Top-level statements) [5]파일 다운로드1
12405정성태11/8/202010584.NET Framework: 965. C# 9.0 - (14) 부분 메서드에 대한 새로운 기능(New features for partial methods)파일 다운로드1
12404정성태11/7/202011126.NET Framework: 964. C# 9.0 - (13) 모듈 이니셜라이저(Module initializers)파일 다운로드1
12403정성태11/7/202011163.NET Framework: 963. C# 9.0 - (12) foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)파일 다운로드1
12402정성태11/7/202011763.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202010679VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/20207658오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202011376.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/20209903오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/202010058.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/20208382VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/20209683오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/20208121오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
... 46  47  48  [49]  50  51  52  53  54  55  56  57  58  59  60  ...